diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-09-10 00:16:32 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-09-10 00:16:32 +0000 |
commit | aa69d586ead70edd87d66f5d6927a170edd5e90d (patch) | |
tree | df4164c0c560a639df1ae2b400feb79e25cf5fd3 /src | |
parent | 38f56608d99b588bbf33dee7041ef9c9c0a7e946 (diff) | |
download | tor-aa69d586ead70edd87d66f5d6927a170edd5e90d.tar.gz tor-aa69d586ead70edd87d66f5d6927a170edd5e90d.zip |
Make buffer unit tests handle resource leaks properly.
svn:r16823
Diffstat (limited to 'src')
-rw-r--r-- | src/or/test.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/or/test.c b/src/or/test.c index 494fb9c8a5..f0e1f6ae85 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -123,7 +123,7 @@ test_buffers(void) char str[256]; char str2[256]; - buf_t *buf, *buf2; + buf_t *buf = NULL, *buf2 = NULL; const char *cp; int j; @@ -174,6 +174,7 @@ test_buffers(void) } test_eq(buf_datalen(buf), 0); buf_free(buf); + buf = NULL; /* Okay, now make sure growing can work. */ buf = buf_new_with_capacity(16); @@ -262,6 +263,7 @@ test_buffers(void) } buf_free(buf); buf_free(buf2); + buf = buf2 = NULL; buf = buf_new_with_capacity(5); cp = "Testing. This is a moderately long Testing string."; @@ -278,6 +280,7 @@ test_buffers(void) test_eq(-1, buf_find_string_offset(buf, "Testing thing", 13)); test_eq(-1, buf_find_string_offset(buf, "ngx", 3)); buf_free(buf); + buf = NULL; #if 0 { @@ -320,6 +323,7 @@ test_buffers(void) test_eq(i, 6); test_memeq(str+10, (char*)_buf_peek_raw_buffer(buf2), 6); buf_free(buf2); + buf2 = NULL; /* Now test when buffer is filled with more data to read. */ buf2 = buf_new_with_capacity(32); @@ -329,6 +333,7 @@ test_buffers(void) test_eq(eof, 0); test_eq(i, 32); buf_free(buf2); + buf2 = NULL; /* Now read to eof. */ test_assert(buf_capacity(buf) > 256); @@ -348,7 +353,10 @@ test_buffers(void) #endif done: - ; + if (buf) + buf_free(buf); + if (buf2) + buf_free(buf2); } static void |