Skip to content

Commit a4d8ba2

Browse files
committed
trurl: use curl_free() on a pointer coming from curl_maprintf()
One instance of a pointer coming from curl_maprintf() was freed with a normal free() which breaks and causes ASAN/valgrind to complain when using a debug-enabled libcurl. Since the function could return a normal heap-allocated pointer or a curl-allocated one, copy the string and curl_free() the original. Closes #393
1 parent 0ce73c1 commit a4d8ba2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

trurl.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ static struct string *memdupzero(char *source, size_t len, bool *modified)
13811381
int rlen;
13821382
int leftside;
13831383
int rightside;
1384+
char *temp;
13841385

13851386
/* decode both sides */
13861387
leftside = (int)(sep - source);
@@ -1420,7 +1421,12 @@ static struct string *memdupzero(char *source, size_t len, bool *modified)
14201421
goto error;
14211422
}
14221423

1423-
encode = curl_maprintf("%s=%s", el ? el : "", er ? er : "");
1424+
temp = curl_maprintf("%s=%s", el ? el : "", er ? er : "");
1425+
if(!temp)
1426+
goto error;
1427+
/* pointers from curl_maprintf() must be curl_free()d so make a copy */
1428+
encode = strdup(temp);
1429+
curl_free(temp);
14241430
if(!encode)
14251431
goto error;
14261432
}

0 commit comments

Comments
 (0)