]> granicus.if.org Git - transmission/commitdiff
Fix memory leaks found by GCC's -address=sanitize (reported by milloni)
authorMike Gelfand <mikedld@mikedld.com>
Tue, 17 Jan 2017 20:55:34 +0000 (23:55 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Tue, 17 Jan 2017 20:55:34 +0000 (23:55 +0300)
Fixes: #56
libtransmission/session.c
libtransmission/variant-benc.c
libtransmission/watchdir-test.c

index 944dde2ad1ce495dc979d17a12dfb3cb93049845..807154b6fa5a64048904fe794716c75fdb07a74c 100644 (file)
@@ -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;
index 275c16066a6fe4f9ee8503f95b05d9923bf8d125..519e40497acad0f7b6a44e0bd3e147ec8b9d6a7e 100644 (file)
@@ -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;
index 84229372b105937df43612d1dbab038bf952b9ec..2bb2de681555f08061e85ace17d3bc44d216ea77 100644 (file)
@@ -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);