[Xfce4-commits] <midori:master> Avoid memory allocated sig in adblock_is_matched_by_key

Christian Dywan noreply at xfce.org
Mon Nov 28 21:06:02 CET 2011


Updating branch refs/heads/master
         to 249619a631988bd7cd9c49739f28be7343965959 (commit)
       from f8b6792756bf2bd1b1590dae776b3bffa040bf53 (commit)

commit 249619a631988bd7cd9c49739f28be7343965959
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Mon Nov 28 20:58:57 2011 +0100

    Avoid memory allocated sig in adblock_is_matched_by_key

 extensions/adblock.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index cbd0072..4e5ae06 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -648,6 +648,7 @@ adblock_is_matched_by_key (const gchar* req_uri,
     GList* regex_bl = NULL;
     GString* guri;
     gboolean ret = FALSE;
+    gchar sig[SIGNATURE_SIZE + 1];
 
     /* Signatures are made on pattern, so we need to convert url to a pattern as well */
     guri = adblock_fixup_regexp ("", (gchar*)req_uri);
@@ -656,21 +657,17 @@ adblock_is_matched_by_key (const gchar* req_uri,
 
     for (pos = len - SIGNATURE_SIZE; pos >= 0; pos--)
     {
-        gchar* sig = g_strndup (uri + pos, SIGNATURE_SIZE);
-        GRegex* regex = g_hash_table_lookup (keys, sig);
+        GRegex* regex;
+        strncpy (sig, uri + pos, SIGNATURE_SIZE);
+        regex = g_hash_table_lookup (keys, sig);
 
         /* Dont check if regex is already blacklisted */
         if (!regex || g_list_find (regex_bl, regex))
-        {
-            g_free (sig);
             continue;
-        }
         ret = adblock_check_rule (regex, sig, req_uri, page_uri);
-        g_free (sig);
         if (!ret)
-            regex_bl = g_list_prepend (regex_bl, regex);
-        else
             break;
+        regex_bl = g_list_prepend (regex_bl, regex);
     }
     g_string_free (guri, TRUE);
     g_list_free (regex_bl);


More information about the Xfce4-commits mailing list