From 514c9c73b1f8de48aad7cc23f6e025de70271103 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 20 Nov 2018 21:51:22 +0000 Subject: [PATCH] Fix 2 more memory leaks Discovered by running `./script/ci-build-plugin tests` locally. Both were caused by not cleaning up on error. --- src/eval.cpp | 10 ++++++++-- src/sass_values.cpp | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/eval.cpp b/src/eval.cpp index 4574192ef..a011f1f4c 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -1103,9 +1103,15 @@ namespace Sass { } union Sass_Value* c_val = c_func(c_args, c_function, compiler()); if (sass_value_get_tag(c_val) == SASS_ERROR) { - error("error in C function " + c->name() + ": " + sass_error_get_message(c_val), c->pstate(), traces); + std::string message("error in C function " + c->name() + ": " + sass_error_get_message(c_val)); + sass_delete_value(c_val); + sass_delete_value(c_args); + error(message, c->pstate(), traces); } else if (sass_value_get_tag(c_val) == SASS_WARNING) { - error("warning in C function " + c->name() + ": " + sass_warning_get_message(c_val), c->pstate(), traces); + std::string message("warning in C function " + c->name() + ": " + sass_warning_get_message(c_val)); + sass_delete_value(c_val); + sass_delete_value(c_args); + error(message, c->pstate(), traces); } result = c2ast(c_val, traces, c->pstate()); diff --git a/src/sass_values.cpp b/src/sass_values.cpp index 34c591a24..4927ee20d 100644 --- a/src/sass_values.cpp +++ b/src/sass_values.cpp @@ -290,7 +290,7 @@ extern "C" { union Sass_Value* ADDCALL sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b) { - Sass::Value_Ptr rv; + Sass::Value_Obj rv; try { @@ -341,8 +341,7 @@ extern "C" { if (!rv) return sass_make_error("invalid return value"); // convert result back to ast node - return ast_node_to_sass_value(rv); - + return ast_node_to_sass_value(rv.ptr()); } // simply pass the error message back to the caller for now