From e7abfdd373d5e3384560103d3eaa50b7606f1981 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 2 Mar 2016 20:40:13 -0800 Subject: [PATCH] Prevent string assertion failures from creating later memory leak errors --- spec/runtime/document_spec.cc | 5 +++-- spec/runtime/parser_spec.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/runtime/document_spec.cc b/spec/runtime/document_spec.cc index 5da23b4f..b4c1fa51 100644 --- a/spec/runtime/document_spec.cc +++ b/spec/runtime/document_spec.cc @@ -26,9 +26,10 @@ describe("Document", [&]() { }); auto assert_node_string_equals = [&](TSNode node, const string &expected) { - char *actual = ts_node_string(node, doc); + char *str = ts_node_string(node, doc); + string actual(str); + ts_free(str); AssertThat(actual, Equals(expected)); - ts_free(actual); }; describe("set_input(input)", [&]() { diff --git a/spec/runtime/parser_spec.cc b/spec/runtime/parser_spec.cc index 4865960f..684cdf56 100644 --- a/spec/runtime/parser_spec.cc +++ b/spec/runtime/parser_spec.cc @@ -77,9 +77,10 @@ describe("Parser", [&]() { auto assert_root_node = [&](const string &expected) { TSNode node = ts_document_root_node(doc); - char *actual = ts_node_string(node, doc); + char *str = ts_node_string(node, doc); + string actual(str); + ts_free(str); AssertThat(actual, Equals(expected)); - ts_free(actual); }; describe("handling errors", [&]() {