libfreerdp-core: fix a few memory leaks in HTTP and RPC code

This commit is contained in:
Marc-André Moreau 2012-05-06 00:53:07 -04:00
parent 3266888ae5
commit bfa4e5b1a2
2 changed files with 41 additions and 1 deletions

View File

@ -35,41 +35,65 @@ HttpContext* http_context_new()
void http_context_set_method(HttpContext* http_context, char* method) void http_context_set_method(HttpContext* http_context, char* method)
{ {
if (http_context->Method)
xfree(http_context->Method);
http_context->Method = xstrdup(method); http_context->Method = xstrdup(method);
} }
void http_context_set_uri(HttpContext* http_context, char* uri) void http_context_set_uri(HttpContext* http_context, char* uri)
{ {
if (http_context->URI)
xfree(http_context->URI);
http_context->URI = xstrdup(uri); http_context->URI = xstrdup(uri);
} }
void http_context_set_user_agent(HttpContext* http_context, char* user_agent) void http_context_set_user_agent(HttpContext* http_context, char* user_agent)
{ {
if (http_context->UserAgent)
xfree(http_context->UserAgent);
http_context->UserAgent = xstrdup(user_agent); http_context->UserAgent = xstrdup(user_agent);
} }
void http_context_set_host(HttpContext* http_context, char* host) void http_context_set_host(HttpContext* http_context, char* host)
{ {
if (http_context->Host)
xfree(http_context->Host);
http_context->Host = xstrdup(host); http_context->Host = xstrdup(host);
} }
void http_context_set_accept(HttpContext* http_context, char* accept) void http_context_set_accept(HttpContext* http_context, char* accept)
{ {
if (http_context->Accept)
xfree(http_context->Accept);
http_context->Accept = xstrdup(accept); http_context->Accept = xstrdup(accept);
} }
void http_context_set_cache_control(HttpContext* http_context, char* cache_control) void http_context_set_cache_control(HttpContext* http_context, char* cache_control)
{ {
if (http_context->CacheControl)
xfree(http_context->CacheControl);
http_context->CacheControl = xstrdup(cache_control); http_context->CacheControl = xstrdup(cache_control);
} }
void http_context_set_connection(HttpContext* http_context, char* connection) void http_context_set_connection(HttpContext* http_context, char* connection)
{ {
if (http_context->Connection)
xfree(http_context->Connection);
http_context->Connection = xstrdup(connection); http_context->Connection = xstrdup(connection);
} }
void http_context_set_pragma(HttpContext* http_context, char* pragma) void http_context_set_pragma(HttpContext* http_context, char* pragma)
{ {
if (http_context->Pragma)
xfree(http_context->Pragma);
http_context->Pragma = xstrdup(pragma); http_context->Pragma = xstrdup(pragma);
} }
@ -89,21 +113,33 @@ void http_context_free(HttpContext* http_context)
void http_request_set_method(HttpRequest* http_request, char* method) void http_request_set_method(HttpRequest* http_request, char* method)
{ {
if (http_request->Method)
xfree(http_request->Method);
http_request->Method = xstrdup(method); http_request->Method = xstrdup(method);
} }
void http_request_set_uri(HttpRequest* http_request, char* uri) void http_request_set_uri(HttpRequest* http_request, char* uri)
{ {
if (http_request->URI)
xfree(http_request->URI);
http_request->URI = xstrdup(uri); http_request->URI = xstrdup(uri);
} }
void http_request_set_auth_scheme(HttpRequest* http_request, char* auth_scheme) void http_request_set_auth_scheme(HttpRequest* http_request, char* auth_scheme)
{ {
if (http_request->AuthScheme)
xfree(http_request->AuthScheme);
http_request->AuthScheme = xstrdup(auth_scheme); http_request->AuthScheme = xstrdup(auth_scheme);
} }
void http_request_set_auth_param(HttpRequest* http_request, char* auth_param) void http_request_set_auth_param(HttpRequest* http_request, char* auth_param)
{ {
if (http_request->AuthParam)
xfree(http_request->AuthParam);
http_request->AuthParam = xstrdup(auth_param); http_request->AuthParam = xstrdup(auth_param);
} }
@ -316,7 +352,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
HttpResponse* http_response; HttpResponse* http_response;
nbytes = 0; nbytes = 0;
length = 0xFFFF; length = 10000;
buffer = xmalloc(length); buffer = xmalloc(length);
http_response = http_response_new(); http_response = http_response_new();
@ -392,6 +428,8 @@ HttpResponse* http_response_recv(rdpTls* tls)
} }
} }
xfree(buffer);
return http_response; return http_response;
} }

View File

@ -203,6 +203,8 @@ STREAM* rpc_ntlm_http_request(rdpRpc* rpc, SecBuffer* ntlm_token, int content_le
s = http_request_write(http_context, http_request); s = http_request_write(http_context, http_request);
http_request_free(http_request); http_request_free(http_request);
xfree(base64_ntlm_token);
return s; return s;
} }