Skip to content

Commit 3fcc098

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 3fcc098

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
TARGET = trurl
2626
OBJS = trurl.o
2727
ifndef TRURL_IGNORE_CURL_CONFIG
28-
LDLIBS += $$(curl-config --libs)
28+
LDLIBS += $$(curl-config --static-libs)
2929
CFLAGS += $$(curl-config --cflags)
3030
endif
3131
CFLAGS += -W -Wall -Wshadow -pedantic

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)