mirror of https://github.com/moparisthebest/curl
fix OOM handling
This commit is contained in:
parent
9e1294e866
commit
02fc7bb5f6
|
@ -77,8 +77,9 @@ static Curl_addrinfo *fake_ai(void)
|
||||||
|
|
||||||
int test(char *URL)
|
int test(char *URL)
|
||||||
{
|
{
|
||||||
CURL *easyh;
|
CURL *easyh = NULL;
|
||||||
struct curl_hash *hp;
|
struct curl_hash *hp = NULL;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
if(!strcmp(URL, "check")) {
|
if(!strcmp(URL, "check")) {
|
||||||
/* test harness script verifying if this test can run */
|
/* test harness script verifying if this test can run */
|
||||||
|
@ -88,7 +89,8 @@ int test(char *URL)
|
||||||
easyh = curl_easy_init();
|
easyh = curl_easy_init();
|
||||||
if(!easyh) {
|
if(!easyh) {
|
||||||
fprintf(stdout, "easy handle init failed\n");
|
fprintf(stdout, "easy handle init failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "easy handle init OK\n");
|
fprintf(stdout, "easy handle init OK\n");
|
||||||
|
|
||||||
|
@ -96,7 +98,8 @@ int test(char *URL)
|
||||||
hp = Curl_mk_dnscache();
|
hp = Curl_mk_dnscache();
|
||||||
if(!hp) {
|
if(!hp) {
|
||||||
fprintf(stdout, "hash creation failed\n");
|
fprintf(stdout, "hash creation failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "hash creation OK\n");
|
fprintf(stdout, "hash creation OK\n");
|
||||||
|
|
||||||
|
@ -111,26 +114,36 @@ int test(char *URL)
|
||||||
data_key = aprintf("%s:%d", "dummy", 0);
|
data_key = aprintf("%s:%d", "dummy", 0);
|
||||||
if(!data_key) {
|
if(!data_key) {
|
||||||
fprintf(stdout, "data key creation failed\n");
|
fprintf(stdout, "data key creation failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
key_len = strlen(data_key);
|
key_len = strlen(data_key);
|
||||||
|
|
||||||
data_node = calloc(1, sizeof(struct Curl_dns_entry));
|
data_node = calloc(1, sizeof(struct Curl_dns_entry));
|
||||||
if(!data_node) {
|
if(!data_node) {
|
||||||
fprintf(stdout, "data node creation failed\n");
|
fprintf(stdout, "data node creation failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
free(data_key);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
data_node->addr = fake_ai();
|
data_node->addr = fake_ai();
|
||||||
if(!data_node->addr) {
|
if(!data_node->addr) {
|
||||||
fprintf(stdout, "actual data creation failed\n");
|
fprintf(stdout, "actual data creation failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
free(data_node);
|
||||||
|
free(data_key);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
|
nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
|
||||||
if(!nodep) {
|
if(!nodep) {
|
||||||
fprintf(stdout, "insertion into hash failed\n");
|
fprintf(stdout, "insertion into hash failed\n");
|
||||||
return TEST_ERR_MAJOR_BAD;
|
result = TEST_ERR_MAJOR_BAD;
|
||||||
|
Curl_freeaddrinfo(data_node->addr);
|
||||||
|
free(data_node);
|
||||||
|
free(data_key);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data_key);
|
free(data_key);
|
||||||
|
@ -138,6 +151,8 @@ int test(char *URL)
|
||||||
#endif /* LIB559 */
|
#endif /* LIB559 */
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
|
||||||
fprintf(stdout, "destroying hash...\n");
|
fprintf(stdout, "destroying hash...\n");
|
||||||
Curl_hash_destroy(hp);
|
Curl_hash_destroy(hp);
|
||||||
fprintf(stdout, "hash destruction OK\n");
|
fprintf(stdout, "hash destruction OK\n");
|
||||||
|
|
Loading…
Reference in New Issue