]> granicus.if.org Git - libevent/commitdiff
Avoid more crashes/bad calls in unit tests; found by coverity
authorNick Mathewson <nickm@torproject.org>
Thu, 26 Jul 2012 14:04:43 +0000 (10:04 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 26 Jul 2012 14:04:43 +0000 (10:04 -0400)
test/regress.c
test/regress_bufferevent.c

index bd2948454b858ee9e05836e3501829f4e8de9f18..5935f9be07108d109ecc63b1fdd32029d396f37d 100644 (file)
@@ -2258,7 +2258,8 @@ end:
                event_free(ev1);
        if (ev2)
                event_free(ev2);
-       close(dfd);
+       if (dfd >= 0)
+               close(dfd);
 }
 #endif
 
index 2a7097ceb3ecf7d01b55433df8281178552f6f39..cdfed0c7005a9ce58772ec030394bf7955f4bd6f 100644 (file)
@@ -243,6 +243,8 @@ test_bufferevent_watermarks_impl(int use_pair)
                bev1 = bufferevent_new(pair[0], NULL, wm_writecb, wm_errorcb, NULL);
                bev2 = bufferevent_new(pair[1], wm_readcb, NULL, wm_errorcb, NULL);
        }
+       tt_assert(bev1);
+       tt_assert(bev2);
        bufferevent_disable(bev1, EV_READ);
        bufferevent_enable(bev2, EV_READ);
 
@@ -267,8 +269,10 @@ test_bufferevent_watermarks_impl(int use_pair)
        tt_assert(!event_pending(&bev2->ev_write, EV_WRITE, NULL));
 
 end:
-       bufferevent_free(bev1);
-       bufferevent_free(bev2);
+       if (bev1)
+               bufferevent_free(bev1);
+       if (bev2)
+               bufferevent_free(bev2);
 }
 
 static void
@@ -377,8 +381,10 @@ test_bufferevent_filters_impl(int use_pair)
                test_ok = 0;
 
 end:
-       bufferevent_free(bev1);
-       bufferevent_free(bev2);
+       if (bev1)
+               bufferevent_free(bev1);
+       if (bev2)
+               bufferevent_free(bev2);
 
 }