[PATCH] Fixed Memory Leak in libid3tag_Get_Frame_Str()



Hi All.

I've tested the new Version 2.2.1 and it is crashing here. In the Process 
debugging and digging around I have found a few Memory Leaks. The Patch 
addresses the first one(s).
I will follow up ;-)

Andreas


---
 src/id3v24_tag.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 85f16c6..4b73ef6 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -667,11 +667,12 @@ libid3tag_Get_Frame_Str(const struct id3_frame *frame, 
unsigned etag_field_type,
 {
     const union id3_field  *field;
     unsigned    i, j, strcnt;
-    gchar   *ret, *tmpstr, *tmpstr2, *latinstr;
+    gchar   *ret, *tmpstr = NULL, *tmpstr2, *latinstr;
     unsigned field_type;
     const id3_ucs4_t *usrc;
     unsigned is_latin, is_utf16;
     unsigned retval;
+    void *fptr;
 
     ret = NULL;
     retval = 0;
@@ -690,7 +691,6 @@ libid3tag_Get_Frame_Str(const struct id3_frame *frame, 
unsigned etag_field_type,
 
     for (i = 0; (field = id3_frame_field(frame, i)); i++)
     {
-        tmpstr = tmpstr2 = NULL;
         switch (field_type = id3_field_type(field))
         {
             case ID3_FIELD_TYPE_LATIN1:
@@ -726,25 +726,31 @@ libid3tag_Get_Frame_Str(const struct id3_frame *frame, 
unsigned etag_field_type,
                 break;
 
             case ID3_FIELD_TYPE_STRINGLIST:
+
                 if (!(etag_field_type & EASYTAG_ID3_FIELD_STRINGLIST))
                     continue;
+               tmpstr2 = NULL;
                 strcnt = id3_field_getnstrings(field);
                 for (j = 0; j < strcnt; j++)
                 {
                     retval |= etag_ucs42gchar(
                         id3_field_getstrings(field, j),
-                        is_latin, is_utf16, &tmpstr );
+                        is_latin, is_utf16, &tmpstr2 );
 
                     if (tmpstr2 && *tmpstr2 && g_utf8_validate(tmpstr2, -1, 
NULL))
                     {
                         if (tmpstr)
+                        {
+                               fptr = tmpstr;
                             tmpstr = g_strconcat(tmpstr, " ", tmpstr2, NULL);
+                            g_free( fptr );
+                        }
                         else
                             tmpstr = g_strdup(tmpstr2);
                     }
-
                     free(tmpstr2);
                 }
+                break;
 
             default:
                 break;
@@ -752,11 +758,16 @@ libid3tag_Get_Frame_Str(const struct id3_frame *frame, 
unsigned etag_field_type,
         if (tmpstr && *tmpstr && g_utf8_validate(tmpstr, -1, NULL))
         {
             if (ret)
+            {
+               fptr = ret;
                 ret = g_strconcat(ret, MULTIFIELD_SEPARATOR, tmpstr, NULL);
+                g_free( fptr );
+            }
             else
                 ret = g_strdup(tmpstr);
         }
         g_free(tmpstr);
+        tmpstr = NULL;
     }
 
     if (retstr)
-- 
1.8.4.5


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