]> granicus.if.org Git - libevent/commitdiff
Avoid close of uninitialized socket in evbuffer unit test
authorNick Mathewson <nickm@torproject.org>
Mon, 17 May 2010 15:58:07 +0000 (11:58 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 17 May 2010 15:58:07 +0000 (11:58 -0400)
Attempts to fix a crash bug found by Brodie Thiesfield.

test/regress_buffer.c

index 85a04a825a2e7dca3a67bfe5b60645510abd2ff4..38ed1a6048f086a0e2eab0a11553302593048496 100644 (file)
@@ -595,7 +595,7 @@ test_evbuffer_add_file(void *ptr)
        const char *data = "this is what we add as file system data.";
        size_t datalen;
        const char *compare;
-       evutil_socket_t fd, pair[2];
+       evutil_socket_t fd = -1, pair[2] = {-1, -1};
        int r=0, n_written=0;
 
        /* Add a test for a big file. XXXX */
@@ -647,8 +647,10 @@ test_evbuffer_add_file(void *ptr)
 
        evbuffer_validate(src);
  end:
-       evutil_closesocket(pair[0]);
-       evutil_closesocket(pair[1]);
+       if (pair[0] >= 0)
+               evutil_closesocket(pair[0]);
+       if (pair[1] >= 0)
+               evutil_closesocket(pair[1]);
        evbuffer_free(src);
 }