leak fixes

Jim Meyering jim at meyering.net
Sun Dec 12 10:18:44 UTC 2010


While working on allowing dynamic provider management,
I've been watching for leaks and have finally fixed
two lingering ones that are unrelated to my work:

>From ddf6a9609e1663eb5444232b77446ae2c5b1da0a Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Sat, 11 Dec 2010 17:43:35 +0100
Subject: [PATCH 1/2] plug leaks-after-OOM-failure

* rest.c (proxy_object_post, proxy_update_prov): Call free_ms
before returning.
---
 rest.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/rest.c b/rest.c
index d07e9b5..bcb32b4 100644
--- a/rest.c
+++ b/rest.c
@@ -1511,6 +1511,7 @@ proxy_object_post (void *cctx, struct MHD_Connection *conn, const char *url,
 				MHD_NO,MHD_NO);
 			if (!resp) {
 				fprintf(stderr,"MHD_crfd failed\n");
+				free_ms(ms);
 				return MHD_NO;
 			}
 			MHD_queue_response(conn,rc,resp);
@@ -1678,8 +1679,8 @@ proxy_update_prov (void *cctx, struct MHD_Connection *conn, const char *url,
 		resp = MHD_create_response_from_data(0,NULL,MHD_NO,MHD_NO);
 		if (!resp) {
 			fprintf(stderr,"MHD_crfd failed\n");
+			free_ms(ms);
 			return MHD_NO;
-			// FIXME: be careful that this does not leak "ms"
 		}
 		MHD_queue_response(conn,rc,resp);
 		MHD_destroy_response(resp);
--
1.7.3.3.26.g4b5f


>From 604fc112cbda1ab89d8c94554055e447ab225c6d Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Sat, 11 Dec 2010 15:41:52 +0100
Subject: [PATCH 2/2] plug a leak

rest.c (proxy_put_data): Plug a leak exposed by reserved-object-name
testing.  Without this, "make -C t check TESTS=basic" with valgrind-
wrapped iwhd would leak one "ms" object per reserved word test here:

    for obj_name in _default _new _policy _query; do
      echo reserved-obj-name | curl -f -T - $bucket/$obj_name \
         2> bad_oname.err
      ...

 2,240 bytes in 4 blocks are definitely lost in loss record 311 of 316
    at 0x4A04896: calloc (vg_replace_malloc.c:418)
    by 0x42EA18: access_handler (rest.c:1967)
    by 0x4E405F8: ??? (in /usr/lib64/libmicrohttpd.so.10.0.0)
    by 0x4E4105F: MHD_connection_handle_idle (in /usr/lib64/libmicrohttpd.so.10.0.0)
    by 0x4E43986: ??? (in /usr/lib64/libmicrohttpd.so.10.0.0)
    by 0x3F49806D5A: start_thread (pthread_create.c:301)
    by 0x3F48CE4AAC: clone (clone.S:115)
---
 rest.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/rest.c b/rest.c
index bcb32b4..aa9854a 100644
--- a/rest.c
+++ b/rest.c
@@ -452,6 +452,7 @@ proxy_put_data (void *cctx, struct MHD_Connection *conn, const char *url,
 			}
 			MHD_queue_response(conn,MHD_HTTP_FORBIDDEN,resp);
 			MHD_destroy_response(resp);
+			free_ms(ms);
 			return MHD_YES;
 		}
 		ms->state = MS_NORMAL;
--
1.7.3.3.26.g4b5f


More information about the iwhd-devel mailing list