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<cJSON>::operator()(cJSON*) const (unique_ptr.h:81)
   by 0xBC4ACA: std::unique_ptr<cJSON, std::default_delete<cJSON> >::~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)
```
This commit is contained in:
George Hilliard
2018-11-02 00:54:02 -05:00
parent 7cbf198db8
commit a63cd8a87c

View File

@@ -419,7 +419,7 @@ std::map<std::string, std::string> getAliases(const Glib::ustring& profile_dir)
buffer[read] = 0; buffer[read] = 0;
cJSON_Minify(buffer.get()); cJSON_Minify(buffer.get());
const std::unique_ptr<cJSON> root(cJSON_Parse(buffer.get())); const std::unique_ptr<cJSON, decltype(&cJSON_Delete)> root(cJSON_Parse(buffer.get()), cJSON_Delete);
if (!root || !root->child) { if (!root || !root->child) {
if (settings->verbose) { if (settings->verbose) {
std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl; std::cout << "Could not parse 'camera_model_aliases.json' file." << std::endl;