Use new[] instead of malloc, because SWIG uses delete[] rather than free.

Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
This commit is contained in:
Keith Rothman
2021-01-15 18:16:30 -08:00
parent 2504197d55
commit 71ff6aa08d

View File

@@ -129,7 +129,8 @@ char * emit_malloc(const c4::yml::Tree &t, size_t id)
c4::substr ret = c4::yml::emit(t, id, buf, /*error_on_excess*/false);
if(ret.str == nullptr && ret.len > 0)
{
char * alloc = static_cast<char*>(malloc(ret.len));
// Use new[] to parse with delete[] in SWIG.
char * alloc = new char[ret.len+1];
c4::substr alloced_buf(alloc, ret.len);
ret = c4::yml::emit(t, id, alloced_buf, /*error_on_excess*/true);
ret.str[ret.len] = 0;