From: Nick Mathewson Date: Mon, 17 May 2010 15:58:07 +0000 (-0400) Subject: Avoid close of uninitialized socket in evbuffer unit test X-Git-Tag: release-2.0.6-rc~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bda21e7ff96dafd679f8308eed5fa9c7e83a2d93;p=libevent Avoid close of uninitialized socket in evbuffer unit test Attempts to fix a crash bug found by Brodie Thiesfield. --- diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 85a04a82..38ed1a60 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -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); }