From fe1d3e2613e68a4acd199a7b7ee49896672fdecf Mon Sep 17 00:00:00 2001 From: Scott West Date: Thu, 2 Oct 2014 23:17:30 +0200 Subject: [PATCH] Fix memory leak in Dict.remove. The entry was previously just overwritten. Now it is saved and the key and object are freed. --- poppler/Dict.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/poppler/Dict.cc b/poppler/Dict.cc index 4cf42dc..201ba5b 100644 --- a/poppler/Dict.cc +++ b/poppler/Dict.cc @@ -193,11 +193,13 @@ GBool Dict::hasKey(const char *key) { } void Dict::remove(const char *key) { + DictEntry deleted_entry; dictLocker(); if (sorted) { const int pos = binarySearch(key, entries, length); if (pos != -1) { length -= 1; + deleted_entry = entries[pos]; if (pos != length) { memmove(&entries[pos], &entries[pos + 1], (length - pos) * sizeof(DictEntry)); } @@ -220,11 +222,15 @@ void Dict::remove(const char *key) { return; } //replace the deleted entry with the last entry + deleted_entry = entries[i]; length -= 1; tmp = entries[length]; if (i!=length) //don't copy the last entry if it is deleted entries[i] = tmp; } + + gfree(deleted_entry.key); + deleted_entry.val.free(); } void Dict::set(const char *key, Object *val) { -- 2.1.2