From bec809cb2ee0136a911c1229d9a6f03c4904ed86 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Sun, 25 Jun 2017 22:59:55 +0200 Subject: test1537: fixed memory leak on OOM --- tests/libtest/lib1537.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/libtest/lib1537.c b/tests/libtest/lib1537.c index d449164e4..b07d64fc5 100644 --- a/tests/libtest/lib1537.c +++ b/tests/libtest/lib1537.c @@ -25,8 +25,8 @@ int test(char *URL) { - unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7}; + const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7}; CURLcode res = CURLE_OK; char *ptr = NULL; int asize; @@ -49,6 +49,10 @@ int test(char *URL) /* deprecated API */ ptr = curl_escape((char *)a, asize); printf("%s\n", ptr); + if(!ptr) { + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen); printf("outlen == %d\n", outlen); @@ -59,6 +63,10 @@ int test(char *URL) /* deprecated API */ raw = curl_unescape(ptr, (int)strlen(ptr)); + if(!raw) { + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } outlen = (int)strlen(raw); printf("[old] outlen == %d\n", outlen); printf("[old] unescape == original? %s\n", @@ -77,6 +85,9 @@ int test(char *URL) ptr = curl_easy_unescape(NULL, (char *)"moahahaha", -1, &outlen); printf("unescape -1 length: %s %d\n", ptr, outlen); +test_cleanup: + if(ptr) + curl_free(ptr); curl_global_cleanup(); return (int)res; -- cgit v1.2.1