]> granicus.if.org Git - libevent/commitdiff
Fix a memory leak on error in evhttp_uriencode
authorNick Mathewson <nickm@torproject.org>
Tue, 17 Jul 2012 15:08:25 +0000 (11:08 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 17 Jul 2012 15:08:25 +0000 (11:08 -0400)
If we ran out of memory in evhttp_uriencode when allocating the
output buffer, we would neglect to call evbuffer_free() on our
temporary buffer.  Now we always free the temporary buffer.

Fixes sourceforge issue 3539887. Thanks to Andrew Cox for reporting
this one.

http.c

diff --git a/http.c b/http.c
index b9687df67196903938fd58d493bcc949d341645f..b9714d333d6d2271fdb523e586203dc0bdcff577 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2685,9 +2685,8 @@ evhttp_uriencode(const char *uri, ev_ssize_t len, int space_as_plus)
        }
        evbuffer_add(buf, "", 1); /* NUL-terminator. */
        result = mm_malloc(evbuffer_get_length(buf));
-       if (!result)
-               return NULL;
-       evbuffer_remove(buf, result, evbuffer_get_length(buf));
+       if (result)
+               evbuffer_remove(buf, result, evbuffer_get_length(buf));
        evbuffer_free(buf);
 
        return (result);