Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak and a serious bug (#23)
User "tycho-kirchner" discovered a memory bug (issue-22) that was caused when the same key is inserted multiple times into OrderedMap. This was a minor oversight that caused a major bug in OrderedMaps's functionality. When inserting an existing key in the map, I delete the corresponding entry in the linked list using the iterator stored, and re-insert the key to the end of the linked list. However, I did not add back this new iterator and value into the hashmap (OMHash). This meant that the the key was holding the old value and an invalid iterator. Because the old iterator pointed to an entry in linked list which was deleted/free'd, it resulted in a memory leak (valgrind would show this memory as unreachable and hence "leaking"). Fix was to add the new value-iterator pair into OMHash for the key being inserted. Updated unit tests to test for this condition.
- Loading branch information