]> granicus.if.org Git - libevent/commitdiff
Fix some memory leaks in the unit tests
authorNick Mathewson <nickm@torproject.org>
Sat, 13 Mar 2010 05:55:39 +0000 (00:55 -0500)
committerNick Mathewson <nickm@torproject.org>
Sat, 13 Mar 2010 05:56:07 +0000 (00:56 -0500)
These don't matter except inasmuch as they give real memory leaks
a place to hide.

Found with valgrind

test/regress_bufferevent.c
test/regress_dns.c
test/regress_http.c
test/regress_listener.c
test/regress_rpc.c
test/regress_zlib.c

index 1960077bc777bd7dffe658b02c62109f10a68957..49ec004b611826b50f8c4ff76a9424a844a5cd01 100644 (file)
@@ -345,10 +345,10 @@ test_bufferevent_filters_impl(int use_pair)
                buffer[i] = i;
 
        bev1 = bufferevent_filter_new(bev1, NULL, bufferevent_output_filter,
-                                     0, NULL, NULL);
+                                     BEV_OPT_CLOSE_ON_FREE, NULL, NULL);
 
        bev2 = bufferevent_filter_new(bev2, bufferevent_input_filter,
-                                     NULL, 0, NULL, NULL);
+                                     NULL, BEV_OPT_CLOSE_ON_FREE, NULL, NULL);
        bufferevent_setcb(bev1, NULL, writecb, errorcb, NULL);
        bufferevent_setcb(bev2, readcb, NULL, errorcb, NULL);
 
index cb3e135cbedd34c0efabd354091f4b14718ac4e8..2ffd94b80004f5b9bbc6ef9bde5919cf5c23ec37 100644 (file)
@@ -438,7 +438,9 @@ struct generic_dns_callback_result {
        char type;
        int count;
        int ttl;
+       size_t addrs_len;
        void *addrs;
+       char addrs_buf[256];
 };
 
 static void
@@ -459,12 +461,15 @@ generic_dns_callback(int result, char type, int count, int ttl, void *addresses,
        else if (type == DNS_PTR)
                len = strlen(addresses)+1;
        else {
-               len = 0;
+               res->addrs_len = len = 0;
                res->addrs = NULL;
        }
        if (len) {
-               res->addrs = malloc(len);
-               memcpy(res->addrs, addresses, len);
+               res->addrs_len = len;
+               if (len > 256)
+                       len = 256;
+               memcpy(res->addrs_buf, addresses, len);
+               res->addrs = res->addrs_buf;
        }
 
        if (--n_replies_left == 0)
index 43e1d08305b22831aba6eb8dfb6afbeaa26a4d25..e2c8078eea27059e9acfd22418aba539b21cf576 100644 (file)
@@ -495,7 +495,7 @@ static void
 http_bad_request_test(void)
 {
        struct timeval tv;
-       struct bufferevent *bev;
+       struct bufferevent *bev = NULL;
        evutil_socket_t fd;
        const char *http_request;
        short port = -1;
@@ -564,6 +564,8 @@ http_bad_request_test(void)
 
 end:
        evhttp_free(http);
+       if (bev)
+               bufferevent_free(bev);
 }
 
 static struct evhttp_connection *delayed_client;
@@ -2530,7 +2532,7 @@ static void
 terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
 {
        struct terminate_state *state = arg;
-       struct evbuffer *evb = evbuffer_new();
+       struct evbuffer *evb;
        struct timeval tv;
 
        if (evhttp_request_get_connection(state->req) == NULL) {
@@ -2540,6 +2542,7 @@ terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
                return;
        }
 
+       evb = evbuffer_new();
        evbuffer_add_printf(evb, "%p", evb);
        evhttp_send_reply_chunk(state->req, evb);
        evbuffer_free(evb);
index 80adad03d4439d8440b21e53195104bd5a232ca9..b2e61468e7ec58033dbeb9013bc1ec2648c7381c 100644 (file)
@@ -127,6 +127,10 @@ end:
                EVUTIL_CLOSESOCKET(fd2);
        if (fd3>=0)
                EVUTIL_CLOSESOCKET(fd3);
+       if (listener1)
+               evconnlistener_free(listener1);
+       if (listener2)
+               evconnlistener_free(listener2);
 }
 
 
index 3b6cdf38b4969b0dcf196f389ad14c5c67b17d3a..482f9a77737c1c30551cee9a8072b0432c33f89c 100644 (file)
@@ -592,6 +592,7 @@ rpc_hook_pause_cb(evutil_socket_t fd, short what, void *arg)
        struct _rpc_hook_ctx *ctx = arg;
        ++hook_pause_cb_called;
        evrpc_resume_request(ctx->vbase, ctx->ctx, EVRPC_CONTINUE);
+       free(arg);
 }
 
 static int
index d20f29f320ea1ae40304e06e15e577d126455bad..a301eaf3cbf072fc1f90a6b469bf2fa26a9f80e5 100644 (file)
@@ -275,10 +275,10 @@ test_bufferevent_zlib(void *arg)
        r = inflateInit(&z_input);
 
        /* initialize filters */
-       bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter, 0,
-           zlib_deflate_free, &z_output);
+       bev1 = bufferevent_filter_new(bev1, NULL, zlib_output_filter,
+           BEV_OPT_CLOSE_ON_FREE, zlib_deflate_free, &z_output);
        bev2 = bufferevent_filter_new(bev2, zlib_input_filter,
-           NULL, 0, zlib_inflate_free, &z_input);
+           NULL, BEV_OPT_CLOSE_ON_FREE, zlib_inflate_free, &z_input);
        bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL);
        bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);