[Python-modules-commits] [pycurl] 109/140: fix a memory leak in reset() function

Barry Warsaw barry at moszumanska.debian.org
Wed Oct 1 21:45:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

barry pushed a commit to branch master
in repository pycurl.

commit f1f824a6ac7748bba16542d524239a9c9d4e3555
Author: Örjan Persson <orjan at spotify.com>
Date:   Fri Jun 14 20:14:33 2013 +0200

    fix a memory leak in reset() function
    
    
    Patch-Name: 50_dont_leak_user_agent.patch
---
 src/pycurl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/pycurl.c b/src/pycurl.c
index ed0c0e5..82ea5b7 100644
--- a/src/pycurl.c
+++ b/src/pycurl.c
@@ -98,6 +98,9 @@ static void pycurl_ssl_cleanup(void);
 #define OPTIONS_SIZE    ((int)CURLOPT_LASTENTRY % 10000)
 #define MOPTIONS_SIZE   ((int)CURLMOPT_LASTENTRY % 10000)
 
+/* Keep some default variables around */
+static const char g_pycurl_useragent[7 + sizeof(LIBCURL_VERSION) + 1];
+
 /* Type objects */
 static PyObject *ErrorObject = NULL;
 static PyTypeObject *p_Curl_Type = NULL;
@@ -780,14 +783,8 @@ util_curl_init(CurlObject *self)
     }
 
     /* Set default USERAGENT */
-    s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1);
-    if (s == NULL) {
-        return (-1);
-    }
-    strcpy(s, "PycURL/"); strcpy(s+7, LIBCURL_VERSION);
-    res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) s);
+    res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) g_pycurl_useragent);
     if (res != CURLE_OK) {
-        free(s);
         return (-1);
     }
     return (0);
@@ -3953,6 +3950,9 @@ initpycurl(void)
         assert(0);
     }
 
+    strcpy(g_pycurl_useragent, "PycURL/");
+    strcpy(g_pycurl_useragent+7, LIBCURL_VERSION);
+
     /* Initialize callback locks if ssl is enabled */
 #if defined(PYCURL_NEED_SSL_TSL)
     pycurl_ssl_init();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pycurl.git



More information about the Python-modules-commits mailing list