diff options
author | Even Rouault <even.rouault@spatialys.com> | 2022-12-13 19:04:26 +0000 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2022-12-13 19:04:26 +0000 |
commit | 06910438d1b2da4cc055bd345e68c3d90101e3fe (patch) | |
tree | abc78745b6f5bc61dfa78c99bd9d549d51da9c92 | |
parent | 393a5ebe496c5da34e971e70085a43795aedfd27 (diff) | |
parent | a03faa56c532faa04b0a7ac574c6f25382433bda (diff) | |
download | libtiff-git-06910438d1b2da4cc055bd345e68c3d90101e3fe.tar.gz |
Merge branch 'TIFFHashSetInsert_memleak_fix' into 'master'v4.5.0rc2
TIFFHashSetInsert(): fix potential memleak
See merge request libtiff/libtiff!443
-rw-r--r-- | libtiff/tif_hash_set.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libtiff/tif_hash_set.c b/libtiff/tif_hash_set.c index 5fbfbbea..49718ce2 100644 --- a/libtiff/tif_hash_set.c +++ b/libtiff/tif_hash_set.c @@ -433,7 +433,8 @@ static void **TIFFHashSetFindPtr(TIFFHashSet *set, const void *elt) * @param set the hash set * @param elt the new element to insert in the hash set * - * @return true if success + * @return true if success. If false is returned, elt has not been inserted, + * but TIFFHashSetInsert() will have run the free function if provided. */ bool TIFFHashSetInsert(TIFFHashSet *set, void *elt) @@ -457,6 +458,8 @@ bool TIFFHashSetInsert(TIFFHashSet *set, void *elt) if (!TIFFHashSetRehash(set)) { set->nIndiceAllocatedSize--; + if (set->fnFreeEltFunc) + set->fnFreeEltFunc(elt); return false; } } @@ -470,6 +473,8 @@ bool TIFFHashSetInsert(TIFFHashSet *set, void *elt) TIFFList *new_elt = TIFFHashSetGetNewListElt(set); if (new_elt == NULL) { + if (set->fnFreeEltFunc) + set->fnFreeEltFunc(elt); return false; } new_elt->pData = elt; |