Gitweb links:
...log
http://git.netsurf-browser.org/libwapcaplet.git/shortlog/5b1700a8917065508336c1318414daa6abb7ace2
...commit
http://git.netsurf-browser.org/libwapcaplet.git/commit/5b1700a8917065508336c1318414daa6abb7ace2
...tree
http://git.netsurf-browser.org/libwapcaplet.git/tree/5b1700a8917065508336c1318414daa6abb7ace2
The branch, master has been updated
via 5b1700a8917065508336c1318414daa6abb7ace2 (commit)
from 130c1dec2842b5a7f1256816b58ea4d41726c950 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libwapcaplet.git/commit/?id=5b1700a8917065508336c1318414daa6abb7ace2
commit 5b1700a8917065508336c1318414daa6abb7ace2
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>
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 <[email protected]>
diff --git a/include/libwapcaplet/libwapcaplet.h
b/include/libwapcaplet/libwapcaplet.h
index d8cc841..e4c2cc9 100644
--- a/include/libwapcaplet/libwapcaplet.h
+++ b/include/libwapcaplet/libwapcaplet.h
@@ -278,6 +278,10 @@ static inline lwc_error lwc_string_caseless_hash_value(
/**
* Iterate the context and return every string in it.
*
+ * If there are no strings found in the context, then this has the
+ * side effect of removing the global context which will reduce the
+ * chances of false-positives on leak checkers.
+ *
* @param cb The callback to give the string to.
* @param pw The private word for the callback.
*/
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;
}
}
-----------------------------------------------------------------------
Summary of changes:
include/libwapcaplet/libwapcaplet.h | 4 ++++
src/libwapcaplet.c | 12 +++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/libwapcaplet/libwapcaplet.h
b/include/libwapcaplet/libwapcaplet.h
index d8cc841..e4c2cc9 100644
--- a/include/libwapcaplet/libwapcaplet.h
+++ b/include/libwapcaplet/libwapcaplet.h
@@ -278,6 +278,10 @@ static inline lwc_error lwc_string_caseless_hash_value(
/**
* Iterate the context and return every string in it.
*
+ * If there are no strings found in the context, then this has the
+ * side effect of removing the global context which will reduce the
+ * chances of false-positives on leak checkers.
+ *
* @param cb The callback to give the string to.
* @param pw The private word for the callback.
*/
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;
}
}
--
String internment library
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org