[tracker/wip/passive-extraction] extract: Plug a leak



commit c32330ea9c90229d1cee0207c68ee3a66a30ea0e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jan 20 20:17:40 2014 +0100

    extract: Plug a leak
    
    If the string being processed is detected as UTF16, the "utf8"
    variable would already contain a malloc()'ed string, so the
    GString would be leaked altogether.
    
    Then, ensure the string is freed if already converted from UTF16,
    and spare the utf8 validation too, since we already know the string
    is valid utf8.

 src/tracker-extract/tracker-read.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/src/tracker-extract/tracker-read.c b/src/tracker-extract/tracker-read.c
index c9087ef..32db459 100644
--- a/src/tracker-extract/tracker-read.c
+++ b/src/tracker-extract/tracker-read.c
@@ -203,16 +203,19 @@ process_whole_string (GString  *s)
                }
        }
 
-       if (!utf8) {
+       if (utf8) {
+               n_valid_utf8_bytes = utf8_len;
+               g_string_free (s, TRUE);
+       } else {
                utf8_len = s->len;
                utf8 = g_string_free (s, FALSE);
-       }
 
-       /* Get number of valid UTF-8 bytes found */
-       tracker_text_validate_utf8 (utf8,
-                                   utf8_len,
-                                   NULL,
-                                   &n_valid_utf8_bytes);
+               /* Get number of valid UTF-8 bytes found */
+               tracker_text_validate_utf8 (utf8,
+                                           utf8_len,
+                                           NULL,
+                                           &n_valid_utf8_bytes);
+       }
 
        /* A valid UTF-8 file will be that where all read bytes are valid,
         *  with a margin of 3 bytes for the last UTF-8 character which might


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]