mirror of
https://github.com/curl/curl.git
synced 2026-04-15 00:01:41 +03:00
formdata: fix memory leak in OOM situation
Fixes #17390
Follow-up to c26da713e7
Reported-by: Viktor Szakats
Closes #17393
This commit is contained in:
parent
1e4a59f8fd
commit
3ec6aa5c07
1 changed files with 15 additions and 8 deletions
|
|
@ -310,6 +310,19 @@ static CURLFORMcode FormAddCheck(struct FormInfo *first_form,
|
|||
return CURL_FORMADD_OK;
|
||||
}
|
||||
|
||||
/* Shallow cleanup. Remove the newly created chain, the structs only and not
|
||||
the content they point to */
|
||||
static void free_chain(struct curl_httppost *c)
|
||||
{
|
||||
while(c) {
|
||||
struct curl_httppost *next = c->next;
|
||||
if(c->more)
|
||||
free_chain(c->more);
|
||||
free(c);
|
||||
c = next;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
||||
struct curl_httppost **last_post,
|
||||
|
|
@ -648,14 +661,8 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
|
|||
|
||||
(*last_post) = lastnode;
|
||||
}
|
||||
else {
|
||||
/* remove the newly created chain */
|
||||
while(newchain) {
|
||||
struct curl_httppost *next = newchain->next;
|
||||
free(newchain);
|
||||
newchain = next;
|
||||
}
|
||||
}
|
||||
else
|
||||
free_chain(newchain);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue