Skip to content
Snippets Groups Projects
Commit 20f76060 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix CID 174276 various malloc()/realloc() failure handling

Have free_paragraphs() explicitly allow paragraphs to be NULL and
have everything use the fail_return which now free()s ret.
parent 15a9bcfc
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -295,6 +295,9 @@ static void free_paragraphs(struct paragraph *paragraph, int count)
{
int i;
if (paragraph == NULL)
return;
for(i=0; count == -1 || i<count ;i++) {
FREE_AND_NULL(paragraph[i].prefix.bytes);
if (count == -1 && paragraph[i].text == NULL)
......@@ -351,18 +354,14 @@ static struct paragraph *word_unwrap(char *inbuf, int oldlen, BOOL handle_quotes
incol = 0;
/* Start of a new paragraph (ie: after a hard CR) */
newret = realloc(ret, (paragraph+1) * sizeof(struct paragraph));
if (newret == NULL) {
free_paragraphs(ret, paragraph);
return NULL;
}
if (newret == NULL)
goto fail_return;
ret = newret;
ret[paragraph].text = (char *)malloc(alloc_len);
ret[paragraph].len = 0;
ret[paragraph].prefix.bytes = NULL;
if (ret[paragraph].text == NULL) {
free_paragraphs(ret, paragraph+1);
return NULL;
}
if (ret[paragraph].text == NULL)
goto fail_return;
ret[paragraph].alloc_size = alloc_len;
ret[paragraph].text[0] = 0;
if (handle_quotes) {
......@@ -468,10 +467,8 @@ static struct paragraph *word_unwrap(char *inbuf, int oldlen, BOOL handle_quotes
}
newret = realloc(ret, (paragraph+1) * sizeof(struct paragraph));
if (newret == NULL) {
free_paragraphs(ret, paragraph);
return NULL;
}
if (newret == NULL)
goto fail_return;
ret = newret;
memset(&ret[paragraph], 0, sizeof(ret[0]));
......@@ -479,6 +476,7 @@ static struct paragraph *word_unwrap(char *inbuf, int oldlen, BOOL handle_quotes
fail_return:
free_paragraphs(ret, paragraph+1);
free(ret);
return NULL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment