From d36c632c86c720ddb089c1e85afbc9aa273d9990 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Tue, 28 Feb 2023 22:45:28 -0500 Subject: [PATCH] DYNBUF.md: note Curl_dyn_add* calls Curl_dyn_free on failure This is the existing behavior and it has been widely assumed in the codebase. Closes https://github.com/curl/curl/pull/10645 --- docs/DYNBUF.md | 8 ++++++++ lib/dynbuf.c | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/DYNBUF.md b/docs/DYNBUF.md index 41b022c422..b0d39296ba 100644 --- a/docs/DYNBUF.md +++ b/docs/DYNBUF.md @@ -37,6 +37,8 @@ CURLcode Curl_dyn_addn(struct dynbuf *s, const void *mem, size_t len); Append arbitrary data of a given length to the end of the buffer. +If this function fails it calls `Curl_dyn_free` on `dynbuf`. + ## `Curl_dyn_add` ```c @@ -45,6 +47,8 @@ CURLcode Curl_dyn_add(struct dynbuf *s, const char *str); Append a C string to the end of the buffer. +If this function fails it calls `Curl_dyn_free` on `dynbuf`. + ## `Curl_dyn_addf` ```c @@ -53,6 +57,8 @@ CURLcode Curl_dyn_addf(struct dynbuf *s, const char *fmt, ...); Append a `printf()`-style string to the end of the buffer. +If this function fails it calls `Curl_dyn_free` on `dynbuf`. + ## `Curl_dyn_vaddf` ```c @@ -61,6 +67,8 @@ CURLcode Curl_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap); Append a `vprintf()`-style string to the end of the buffer. +If this function fails it calls `Curl_dyn_free` on `dynbuf`. + ## `Curl_dyn_reset` ```c diff --git a/lib/dynbuf.c b/lib/dynbuf.c index 847f6f6ad1..bd3b9356c7 100644 --- a/lib/dynbuf.c +++ b/lib/dynbuf.c @@ -99,8 +99,7 @@ static CURLcode dyn_nappend(struct dynbuf *s, include that as well when it uses this code */ void *p = realloc(s->bufr, a); if(!p) { - Curl_safefree(s->bufr); - s->leng = s->allc = 0; + Curl_dyn_free(s); return CURLE_OUT_OF_MEMORY; } s->bufr = p; -- 2.47.3