From 0ac657c5f1aec17f1f3dab8fdb57be60d5a8e91a Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sun, 25 Dec 2016 19:44:38 +0300 Subject: [PATCH] Fix up rename test to avoid random use-after-free failures --- libtransmission/rename-test.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libtransmission/rename-test.c b/libtransmission/rename-test.c index c3fa01956..3fcf6954d 100644 --- a/libtransmission/rename-test.c +++ b/libtransmission/rename-test.c @@ -84,6 +84,16 @@ torrentRenameAndWait (tr_torrent * tor, return error; } +static void +torrentRemoveAndWait (tr_torrent * tor, + int expected_torrent_count) +{ + tr_torrentRemove (tor, false, NULL); + + while (tr_sessionCountTorrents (session) != expected_torrent_count) + tr_wait_msec (10); +} + /*** **** ***/ @@ -221,7 +231,7 @@ test_single_filename_torrent (void) /* cleanup */ tr_ctorFree (ctor); - tr_torrentRemove (tor, false, NULL); + torrentRemoveAndWait (tor, 0); return 0; } @@ -436,13 +446,7 @@ test_multifile_torrent (void) } tr_ctorFree (ctor); - tr_torrentRemove (tor, false, NULL); - - do - { - tr_wait_msec (10); - } - while (tr_sessionCountTorrents (session) > 0); + torrentRemoveAndWait (tor, 0); /** *** Test renaming prefixes (shouldn't work) @@ -483,7 +487,7 @@ test_multifile_torrent (void) /* cleanup */ tr_ctorFree (ctor); - tr_torrentRemove (tor, false, NULL); + torrentRemoveAndWait (tor, 0); return 0; } @@ -550,7 +554,7 @@ test_partial_file (void) tr_free (expected); } - tr_torrentRemove (tor, false, NULL); + torrentRemoveAndWait (tor, 0); return 0; }