From: Mike Gelfand Date: Tue, 17 Jan 2017 20:55:34 +0000 (+0300) Subject: Fix memory leaks found by GCC's -address=sanitize (reported by milloni) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1f08edf791ede3594964e403082e1efdbac8996;p=transmission Fix memory leaks found by GCC's -address=sanitize (reported by milloni) Fixes: #56 --- diff --git a/libtransmission/session.c b/libtransmission/session.c index 944dde2ad..807154b6f 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -1866,6 +1866,9 @@ sessionCloseImplWaitForIdleUdp (evutil_socket_t foo UNUSED, static void sessionCloseImplFinish (tr_session * session) { + event_free (session->saveTimer); + session->saveTimer = NULL; + /* we had to wait until UDP trackers were closed before closing these: */ evdns_base_free (session->evdns_base, 0); session->evdns_base = NULL; diff --git a/libtransmission/variant-benc.c b/libtransmission/variant-benc.c index 275c16066..519e40497 100644 --- a/libtransmission/variant-benc.c +++ b/libtransmission/variant-benc.c @@ -257,11 +257,19 @@ tr_variantParseBenc (const void * buf_in, break; } - if (!err && (!top->type || !tr_ptrArrayEmpty(&stack))) + if (err == 0 && (top->type == 0 || !tr_ptrArrayEmpty(&stack))) err = EILSEQ; - if (!err && setme_end) - *setme_end = (const char*) buf; + if (err == 0) + { + if (setme_end != NULL) + *setme_end = (const char*) buf; + } + else if (top->type != 0) + { + tr_variantFree (top); + tr_variantInit (top, 0); + } tr_ptrArrayDestruct (&stack, NULL); return err; diff --git a/libtransmission/watchdir-test.c b/libtransmission/watchdir-test.c index 84229372b..2bb2de681 100644 --- a/libtransmission/watchdir-test.c +++ b/libtransmission/watchdir-test.c @@ -127,6 +127,8 @@ test_construct (void) check (wd != NULL); check (tr_sys_path_is_same (test_dir, tr_watchdir_get_path (wd), NULL)); + process_events (); + tr_watchdir_free (wd); event_base_free (ev_base);