diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-07-03 12:02:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-03 12:02:29 -0700 |
commit | 7ae67bd161aa267aa540d30a6683a365f64bef3a (patch) | |
tree | 1a687a13d0d38317f9021054c6194038bd1e9a63 /src | |
parent | 3d6155fe9a49e4a07379b816f9c7c2f00ae33dc4 (diff) | |
parent | 67f760a78f7a875216d9b64aaf3524cc4f9a0f48 (diff) |
Merge pull request #140 from nwellnhof/set-cstr-fix
Fix chunk_set_cstr with suffix of current string
Diffstat (limited to 'src')
-rw-r--r-- | src/chunk.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/chunk.h b/src/chunk.h index 1bea422..a2248f5 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -77,9 +77,7 @@ static CMARK_INLINE const char *cmark_chunk_to_cstr(cmark_mem *mem, static CMARK_INLINE void cmark_chunk_set_cstr(cmark_mem *mem, cmark_chunk *c, const char *str) { - if (c->alloc) { - mem->free(c->data); - } + unsigned char *old = c->alloc ? c->data : NULL; if (str == NULL) { c->len = 0; c->data = NULL; @@ -90,6 +88,9 @@ static CMARK_INLINE void cmark_chunk_set_cstr(cmark_mem *mem, cmark_chunk *c, c->alloc = 1; memcpy(c->data, str, c->len + 1); } + if (old != NULL) { + mem->free(old); + } } static CMARK_INLINE cmark_chunk cmark_chunk_literal(const char *data) { |