summaryrefslogtreecommitdiff
path: root/src/libwapcaplet.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-09-07 14:59:40 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-09-07 14:59:40 +0100
commit5b1700a8917065508336c1318414daa6abb7ace2 (patch)
treeac1f80c00946fee424d8fcf61c18f823620ec5a3 /src/libwapcaplet.c
parent130c1dec2842b5a7f1256816b58ea4d41726c950 (diff)
downloadlibwapcaplet-5b1700a8917065508336c1318414daa6abb7ace2.tar.gz
Remove global context if no strings leak
If when we iterate the context there're no strings, then we can delete the context too, which reduces false-positives on leak checkers. Closes #2490 Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/libwapcaplet.c')
-rw-r--r--src/libwapcaplet.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c
index 9bc1fc9..34a72cd 100644
--- a/src/libwapcaplet.c
+++ b/src/libwapcaplet.c
@@ -271,12 +271,22 @@ lwc_iterate_strings(lwc_iteration_callback_fn cb, void *pw)
{
lwc_hash n;
lwc_string *str;
+ bool found = false;
if (ctx == NULL)
return;
for (n = 0; n < ctx->bucketcount; ++n) {
- for (str = ctx->buckets[n]; str != NULL; str = str->next)
+ for (str = ctx->buckets[n]; str != NULL; str = str->next) {
+ found = true;
cb(str, pw);
+ }
+ }
+
+ if (found == false) {
+ /* We found no strings, so remove the global context. */
+ free(ctx->buckets);
+ free(ctx);
+ ctx = NULL;
}
}