From a63cd8a87c5e5c880d2e64c99f53c70691a68539 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Fri, 2 Nov 2018 00:54:02 -0500 Subject: [PATCH] Fix mismatched malloc/delete leak, take 2 with cJSON_Delete From the Valgrind report: ``` Mismatched free() / delete / delete [] at 0x4838EAB: operator delete(void*) (vg_replace_malloc.c:576) by 0xBC5C87: std::default_delete::operator()(cJSON*) const (unique_ptr.h:81) by 0xBC4ACA: std::unique_ptr >::~unique_ptr() (unique_ptr.h:274) by 0xBBB755: (anonymous namespace)::getAliases(Glib::ustring const&) (dcp.cc:422) by 0xBC1CCA: rtengine::DCPStore::init(Glib::ustring const&, bool) (dcp.cc:1846) by 0xC3ED4F: rtengine::init(rtengine::Settings const*, Glib::ustring, Glib::ustring, bool) [clone ._omp_fn.0] (init.cc:81) by 0x89743FF: GOMP_parallel_sections (sections.c:158) by 0xC3E906: rtengine::init(rtengine::Settings const*, Glib::ustring, Glib::ustring, bool) (init.cc:52) by 0x9CE10E: Options::load(bool) (options.cc:2358) by 0x982CD6: main (main.cc:603) Address 0xd62d700 is 0 bytes inside a block of size 64 alloc'd at 0x483777F: malloc (vg_replace_malloc.c:299) by 0xE97390: cJSON_New_Item (cJSON.c:205) by 0xE98718: cJSON_ParseWithOpts (cJSON.c:1020) by 0xE9886F: cJSON_Parse (cJSON.c:1083) by 0xBBB4D3: (anonymous namespace)::getAliases(Glib::ustring const&) (dcp.cc:422) by 0xBC1CCA: rtengine::DCPStore::init(Glib::ustring const&, bool) (dcp.cc:1846) by 0xC3ED4F: rtengine::init(rtengine::Settings const*, Glib::ustring, Glib::ustring, bool) [clone ._omp_fn.0] (init.cc:81) by 0x89743FF: GOMP_parallel_sections (sections.c:158) by 0xC3E906: rtengine::init(rtengine::Settings const*, Glib::ustring, Glib::ustring, bool) (init.cc:52) by 0x9CE10E: Options::load(bool) (options.cc:2358) by 0x982CD6: main (main.cc:603) ``` --- rtengine/dcp.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index c18ee8915..c60e80587 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -419,7 +419,7 @@ std::map getAliases(const Glib::ustring& profile_dir) buffer[read] = 0; cJSON_Minify(buffer.get()); - const std::unique_ptr root(cJSON_Parse(buffer.get())); + const std::unique_ptr root(cJSON_Parse(buffer.get()), cJSON_Delete); if (!root || !root->child) { if (settings->verbose) { std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl;