-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Hi @ithewei,
thank you for this library! There is a bug in hv::HttpClient, it contains a raw pointer member and defines a destructor, but doesn't define a move/copy constructors and assignment operators (this is the Rule of Three, see here for more information). Therefore, copying / moving hv::HttpClient and subsequent destruction leads to a use after free error.
To fix, replace the raw pointer in hv::HttpClient but a unique_ptr as follows:
#include "hexport.h"
#include "hssl.h"
#include "HttpMessage.h"
#include <memory>
class HttpClient
{
public:
HttpClient(const char* host = nullptr, int port = DEFAULT_HTTP_PORT, int https = 0)
: client_(http_client_new(host, port, https))
{}
// other class members, but no destructor! ....
private:
std::unique_ptr<http_client_t, HttpClientDeleter> client_;
};This fix adheres to the Rule of Zero.
Note that you can delete the definition of the destructor, the auto-generated one will be just right!
Metadata
Metadata
Assignees
Labels
No labels