Skip to content

Commit eb6f5d4

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 eb6f5d4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

trurl.c

Lines changed: 7 additions & 0 deletions
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 *dupencode;
13841385

13851386
/* decode both sides */
13861387
leftside = (int)(sep - source);
@@ -1423,6 +1424,12 @@ static struct string *memdupzero(char *source, size_t len, bool *modified)
14231424
encode = curl_maprintf("%s=%s", el ? el : "", er ? er : "");
14241425
if(!encode)
14251426
goto error;
1427+
/* pointers from curl_maprintf() must be curl_free()d so make a copy */
1428+
dupencode = strdup(encode);
1429+
curl_free(encode);
1430+
encode = dupencode;
1431+
if(!encode)
1432+
goto error;
14261433
}
14271434
olen = (int)strlen(encode);
14281435

0 commit comments

Comments
 (0)