Merge pull request #9090

430b102 Cleanup scoped_ptr in src/common/dns_utils.cpp and header include: 	* No need for entire new class (Fix #8732). 	* Fix stdint.h header include in contrib/epee/include/net/http_base.h. (0xFFFC0000)
This commit is contained in:
luigi1111 2024-01-18 18:06:23 -05:00
commit eb904d709a
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
2 changed files with 11 additions and 34 deletions

View file

@ -34,6 +34,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <list> #include <list>
#include <stdint.h>
#undef MONERO_DEFAULT_LOG_CATEGORY #undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.http" #define MONERO_DEFAULT_LOG_CATEGORY "net.http"

View file

@ -28,6 +28,7 @@
#include "common/dns_utils.h" #include "common/dns_utils.h"
// check local first (in the event of static or in-source compilation of libunbound) // check local first (in the event of static or in-source compilation of libunbound)
#include "misc_language.h"
#include "unbound.h" #include "unbound.h"
#include <deque> #include <deque>
@ -195,36 +196,7 @@ boost::optional<std::string> tlsa_to_string(const char* src, size_t len)
return boost::none; return boost::none;
return std::string(src, len); return std::string(src, len);
} }
// custom smart pointer.
// TODO: see if std::auto_ptr and the like support custom destructors
template<typename type, void (*freefunc)(type*)>
class scoped_ptr
{
public:
scoped_ptr():
ptr(nullptr)
{
}
scoped_ptr(type *p):
ptr(p)
{
}
~scoped_ptr()
{
freefunc(ptr);
}
operator type *() { return ptr; }
type **operator &() { return &ptr; }
type *operator->() { return ptr; }
operator const type*() const { return &ptr; }
private:
type* ptr;
};
typedef class scoped_ptr<ub_result,ub_resolve_free> ub_result_ptr;
struct DNSResolverData struct DNSResolverData
{ {
ub_ctx* m_ub_context; ub_ctx* m_ub_context;
@ -327,10 +299,14 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
std::vector<std::string> addresses; std::vector<std::string> addresses;
dnssec_available = false; dnssec_available = false;
dnssec_valid = false; dnssec_valid = false;
// destructor takes care of cleanup ub_result *result;
ub_result_ptr result; // Make sure we are cleaning after result.
epee::misc_utils::auto_scope_leave_caller scope_exit_handler =
epee::misc_utils::create_scope_leave_handler([&](){
ub_resolve_free(result);
});
MDEBUG("Performing DNSSEC " << get_record_name(record_type) << " record query for " << url); MDEBUG("Performing DNSSEC " << get_record_name(record_type) << " record query for " << url);
// call DNS resolver, blocking. if return value not zero, something went wrong // call DNS resolver, blocking. if return value not zero, something went wrong