Fix memory leaks found by GCC's -address=sanitize (reported by milloni)

Fixes: #56
This commit is contained in:
Mike Gelfand 2017-01-17 23:55:34 +03:00
parent 67bda2dcb8
commit c1f08edf79
3 changed files with 16 additions and 3 deletions

View 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;

View 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;

View 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);