Bladeren bron

Unit test: fix some memory leaks and auto-format code

bel2125 7 jaren geleden
bovenliggende
commit
f4c7414162
2 gewijzigde bestanden met toevoegingen van 12 en 3 verwijderingen
  1. 6 3
      src/civetweb.c
  2. 6 0
      test/public_server.c

+ 6 - 3
src/civetweb.c

@@ -14773,9 +14773,12 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 	                    &sa)) {
 		return NULL;
 	}
-	if ((conn = (struct mg_connection *)mg_calloc_ctx(
-	         1, sizeof(*conn) + max_req_size, &common_client_context))
-	    == NULL) {
+
+	conn = (struct mg_connection *)mg_calloc_ctx(1,
+	                                             sizeof(*conn) + max_req_size,
+	                                             &common_client_context);
+
+	if (conn == NULL) {
 		mg_snprintf(NULL,
 		            NULL, /* No truncation check for ebuf */
 		            ebuf,

+ 6 - 0
test/public_server.c

@@ -2060,6 +2060,10 @@ START_TEST(test_request_handlers)
 	}
 
 	ck_assert_int_eq(ws_client4_data.closed, 1);
+
+	/* Free data in ws_client4_conn */
+	mg_close_connection(ws_client4_conn);
+
 #endif
 	mark_point();
 }
@@ -3165,6 +3169,8 @@ START_TEST(test_http_auth)
 	                    NULL);
 	ck_assert_ptr_eq(HA_md5_ret, HA_md5_buf);
 
+	mg_close_connection(client_conn);
+
 	/* Retry with authorization */
 	memset(client_err, 0, sizeof(client_err));
 	client_conn =