jsonnet
jsonnet copied to clipboard
memory leakages in c++ API
There's not a single jsonnet_realloc
call in https://github.com/google/jsonnet/blob/995e3aeb36d970a9c4ed4cc408314635a9c4b093/cpp/libjsonnet%2B%2B.cpp, presumably memory leaked everywhere.
$ valgrind --leak-check=full ./build/libjsonnet++_test
==7318== Memcheck, a memory error detector
==7318== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==7318== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==7318== Command: ./build/libjsonnet++_test
==7318==
Running main() from /home/xiaolan/repo/jsonnet.git/build/googletest-src/googletest/src/gtest_main.cc
[==========] Running 5 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 5 tests from JsonnetTest
[ RUN ] JsonnetTest.TestEvaluateSnippet
[ OK ] JsonnetTest.TestEvaluateSnippet (984 ms)
[ RUN ] JsonnetTest.TestEvaluateInvalidSnippet
[ OK ] JsonnetTest.TestEvaluateInvalidSnippet (579 ms)
[ RUN ] JsonnetTest.TestEvaluateFile
[ OK ] JsonnetTest.TestEvaluateFile (549 ms)
[ RUN ] JsonnetTest.TestEvaluateInvalidFile
[ OK ] JsonnetTest.TestEvaluateInvalidFile (551 ms)
[ RUN ] JsonnetTest.TestAddImportPath
[ OK ] JsonnetTest.TestAddImportPath (1121 ms)
[----------] 5 tests from JsonnetTest (3792 ms total)
[----------] Global test environment tear-down
[==========] 5 tests from 1 test suite ran. (3826 ms total)
[ PASSED ] 5 tests.
==7318==
==7318== HEAP SUMMARY:
==7318== in use at exit: 165 bytes in 5 blocks
==7318== total heap usage: 678,397 allocs, 678,392 frees, 57,448,188 bytes allocated
==7318==
==7318== 15 bytes in 1 blocks are definitely lost in loss record 1 of 5
==7318== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7318== by 0x1D56E4: jsonnet_realloc (libjsonnet.cpp:696)
==7318== by 0x1D78DF: from_string (libjsonnet.cpp:47)
==7318== by 0x1D78DF: jsonnet_evaluate_snippet_aux(JsonnetVm*, char const*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.356] (libjsonnet.cpp:519)
==7318== by 0x1D7CAA: jsonnet_evaluate_snippet (libjsonnet.cpp:667)
==7318== by 0x1D4FA2: jsonnet::Jsonnet::evaluateSnippet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (libjsonnet++.cpp:114)
==7318== by 0x18C1E1: jsonnet::JsonnetTest_TestEvaluateSnippet_Test::TestBody() (libjsonnet++_test.cpp:44)
==7318== by 0x1C357E: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1BCAA0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1992CF: testing::Test::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x199C54: testing::TestInfo::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x19A34A: testing::TestSuite::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1A5D5C: testing::internal::UnitTestImpl::RunAllTests() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318==
==7318== 15 bytes in 1 blocks are definitely lost in loss record 2 of 5
==7318== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7318== by 0x1D56E4: jsonnet_realloc (libjsonnet.cpp:696)
==7318== by 0x1D78DF: from_string (libjsonnet.cpp:47)
==7318== by 0x1D78DF: jsonnet_evaluate_snippet_aux(JsonnetVm*, char const*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.356] (libjsonnet.cpp:519)
==7318== by 0x1DDCA8: jsonnet_evaluate_file_aux(JsonnetVm*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.354] (libjsonnet.cpp:637)
==7318== by 0x1DDFDA: jsonnet_evaluate_file (libjsonnet.cpp:643)
==7318== by 0x1D4EDF: jsonnet::Jsonnet::evaluateFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (libjsonnet++.cpp:97)
==7318== by 0x18D0B7: jsonnet::JsonnetTest_TestEvaluateFile_Test::TestBody() (libjsonnet++_test.cpp:69)
==7318== by 0x1C357E: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1BCAA0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1992CF: testing::Test::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x199C54: testing::TestInfo::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x19A34A: testing::TestSuite::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318==
==7318== 15 bytes in 1 blocks are definitely lost in loss record 3 of 5
==7318== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7318== by 0x1D56E4: jsonnet_realloc (libjsonnet.cpp:696)
==7318== by 0x1D78DF: from_string (libjsonnet.cpp:47)
==7318== by 0x1D78DF: jsonnet_evaluate_snippet_aux(JsonnetVm*, char const*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.356] (libjsonnet.cpp:519)
==7318== by 0x1DDCA8: jsonnet_evaluate_file_aux(JsonnetVm*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.354] (libjsonnet.cpp:637)
==7318== by 0x1DDFDA: jsonnet_evaluate_file (libjsonnet.cpp:643)
==7318== by 0x1D4EDF: jsonnet::Jsonnet::evaluateFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (libjsonnet++.cpp:97)
==7318== by 0x18DE81: jsonnet::JsonnetTest_TestAddImportPath_Test::TestBody() (libjsonnet++_test.cpp:94)
==7318== by 0x1C357E: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1BCAA0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1992CF: testing::Test::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x199C54: testing::TestInfo::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x19A34A: testing::TestSuite::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318==
==7318== 60 bytes in 1 blocks are definitely lost in loss record 4 of 5
==7318== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7318== by 0x1D56E4: jsonnet_realloc (libjsonnet.cpp:696)
==7318== by 0x1D5722: from_string(JsonnetVm*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (libjsonnet.cpp:47)
==7318== by 0x1D7B8A: jsonnet_evaluate_snippet_aux(JsonnetVm*, char const*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.356] (libjsonnet.cpp:617)
==7318== by 0x1D7CAA: jsonnet_evaluate_snippet (libjsonnet.cpp:667)
==7318== by 0x1D4FA2: jsonnet::Jsonnet::evaluateSnippet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (libjsonnet++.cpp:114)
==7318== by 0x18C9C5: jsonnet::JsonnetTest_TestEvaluateInvalidSnippet_Test::TestBody() (libjsonnet++_test.cpp:57)
==7318== by 0x1C357E: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1BCAA0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1992CF: testing::Test::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x199C54: testing::TestInfo::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x19A34A: testing::TestSuite::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318==
==7318== 60 bytes in 1 blocks are definitely lost in loss record 5 of 5
==7318== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7318== by 0x1D56E4: jsonnet_realloc (libjsonnet.cpp:696)
==7318== by 0x1D5722: from_string(JsonnetVm*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (libjsonnet.cpp:47)
==7318== by 0x1D7B8A: jsonnet_evaluate_snippet_aux(JsonnetVm*, char const*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.356] (libjsonnet.cpp:617)
==7318== by 0x1DDCA8: jsonnet_evaluate_file_aux(JsonnetVm*, char const*, int*, (anonymous namespace)::EvalKind) [clone .constprop.354] (libjsonnet.cpp:637)
==7318== by 0x1DDFDA: jsonnet_evaluate_file (libjsonnet.cpp:643)
==7318== by 0x1D4EDF: jsonnet::Jsonnet::evaluateFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) (libjsonnet++.cpp:97)
==7318== by 0x18D777: jsonnet::JsonnetTest_TestEvaluateInvalidFile_Test::TestBody() (libjsonnet++_test.cpp:81)
==7318== by 0x1C357E: void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1BCAA0: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x1992CF: testing::Test::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318== by 0x199C54: testing::TestInfo::Run() (in /home/xiaolan/repo/jsonnet.git/build/libjsonnet++_test)
==7318==
==7318== LEAK SUMMARY:
==7318== definitely lost: 165 bytes in 5 blocks
==7318== indirectly lost: 0 bytes in 0 blocks
==7318== possibly lost: 0 bytes in 0 blocks
==7318== still reachable: 0 bytes in 0 blocks
==7318== suppressed: 0 bytes in 0 blocks
==7318==
==7318== For counts of detected and suppressed errors, rerun with: -v
==7318== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)
This should be fairly trivial to fix by adding jsonnet_realloc(vm, whatever_variable, 0)
in several places.
See also #845 which I think was reporting the same (or overlapping set of) leaks. I believe this was fixed by #1013. Closing this as complete.