diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-31 12:25:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-31 12:25:49 +0300 |
commit | b8a66973ac79f44c86736eddb6589d5749ad11e6 (patch) | |
tree | a719788fb827e38a6ae0b533b5723bf490ef1cc1 /intern | |
parent | af11eea3fd047007ea0f63f5ad2efbd1390221f3 (diff) |
Fix clog: own error allocating from static buffer
Diffstat (limited to 'intern')
-rw-r--r-- | intern/clog/clog.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/intern/clog/clog.c b/intern/clog/clog.c index 66267dd6df2..e99633a2f81 100644 --- a/intern/clog/clog.c +++ b/intern/clog/clog.c @@ -29,6 +29,7 @@ # include <unistd.h> #endif +/* Only other dependency (could use regular malloc too). */ #include "MEM_guardedalloc.h" /* own include. */ @@ -102,15 +103,21 @@ static void clg_str_free(CLogStringBuf *cstr) static void clg_str_reserve(CLogStringBuf *cstr, const uint len) { if (len > cstr->len_alloc) { - if (cstr->is_alloc == false) { - cstr->is_alloc = true; - cstr->data = NULL; - } cstr->len_alloc *= 2; if (len > cstr->len_alloc) { cstr->len_alloc = len; } - cstr->data = MEM_reallocN(cstr->data, len); + + if (cstr->is_alloc) { + cstr->data = MEM_reallocN(cstr->data, cstr->len_alloc); + } + else { + /* Copy the static buffer. */ + char *data = MEM_mallocN(cstr->len_alloc, __func__); + memcpy(data, cstr->data, cstr->len); + cstr->data = data; + cstr->is_alloc = true; + } cstr->len_alloc = len; } } @@ -400,6 +407,8 @@ void CLG_logf( fwrite(cstr.data, cstr.len, 1, lg->ctx->output); fflush(lg->ctx->output); + clg_str_free(&cstr); + if (severity == CLG_SEVERITY_FATAL) { clg_ctx_fatal_action(lg->ctx, lg->ctx->output); } |