Skip to content

Commit

Permalink
memdupdec: free memory in OOM exit path
Browse files Browse the repository at this point in the history
Detected by Coverity
  • Loading branch information
bagder committed May 14, 2024
1 parent d80d308 commit 2f38b45
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,21 @@ static struct string *memdupdec(char *source, size_t len, bool json)
char *p;
int plen;
right = strurldecode(sep + 1, (int)(len - (sep - source) - 1),
&right_len);
&right_len);

/* convert null bytes to periods */
for(plen = right_len, p = right; plen; plen--, p++) {
if(!*p && !json) {
*p = REPLACE_NULL_BYTE;
}
}
}
}
str = malloc(sizeof(char) * (left_len + (sep?(right_len + 1):0)));
if(!str)
if(!str) {
curl_free(right);
curl_free(left);
return NULL;
}
memcpy(str, left, left_len);
if(sep) {
str[left_len] = '=';
Expand Down

0 comments on commit 2f38b45

Please sign in to comment.