1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

test1537: fixed memory leak on OOM

This commit is contained in:
Dan Fandrich 2017-06-25 22:59:55 +02:00
parent e8a4da67f5
commit bec809cb2e

View File

@ -25,7 +25,7 @@
int test(char *URL) int test(char *URL)
{ {
unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7}; 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
CURLcode res = CURLE_OK; CURLcode res = CURLE_OK;
char *ptr = NULL; char *ptr = NULL;
@ -49,6 +49,10 @@ int test(char *URL)
/* deprecated API */ /* deprecated API */
ptr = curl_escape((char *)a, asize); ptr = curl_escape((char *)a, asize);
printf("%s\n", ptr); printf("%s\n", ptr);
if(!ptr) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen); raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen);
printf("outlen == %d\n", outlen); printf("outlen == %d\n", outlen);
@ -59,6 +63,10 @@ int test(char *URL)
/* deprecated API */ /* deprecated API */
raw = curl_unescape(ptr, (int)strlen(ptr)); raw = curl_unescape(ptr, (int)strlen(ptr));
if(!raw) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
outlen = (int)strlen(raw); outlen = (int)strlen(raw);
printf("[old] outlen == %d\n", outlen); printf("[old] outlen == %d\n", outlen);
printf("[old] unescape == original? %s\n", printf("[old] unescape == original? %s\n",
@ -77,6 +85,9 @@ int test(char *URL)
ptr = curl_easy_unescape(NULL, (char *)"moahahaha", -1, &outlen); ptr = curl_easy_unescape(NULL, (char *)"moahahaha", -1, &outlen);
printf("unescape -1 length: %s %d\n", ptr, outlen); printf("unescape -1 length: %s %d\n", ptr, outlen);
test_cleanup:
if(ptr)
curl_free(ptr);
curl_global_cleanup(); curl_global_cleanup();
return (int)res; return (int)res;