[file-roller] Fix a memory leak of the file content type



commit 3d4a73661df2343d8e18a3f0b8fbe161237ca205
Author: David King <dking redhat com>
Date:   Wed May 11 10:53:38 2016 +0100

    Fix a memory leak of the file content type
    
    ==23889== 42 bytes in 2 blocks are definitely lost in loss record 10,530 of 22,830
    ==23889==    at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
    ==23889==    by 0x73FD038: g_malloc (gmem.c:94)
    ==23889==    by 0x741520E: g_strdup (gstrfuncs.c:363)
    ==23889==    by 0x6E82031: g_content_type_guess (gcontenttype.c:719)
    ==23889==    by 0x41ADA2: file_data_update_content_type (file-data.c:99)
    ==23889==    by 0x420B33: fr_archive_add_file (fr-archive.c:2129)
    ==23889==    by 0x453F61: list_archive_thread (fr-archive-libarchive.c:399)
    ==23889==    by 0x6E50BF0: run_in_thread (gsimpleasyncresult.c:898)
    ==23889==    by 0x6E3D378: io_job_thread (gioscheduler.c:85)
    ==23889==    by 0x6E622EF: g_task_thread_pool_thread (gtask.c:1288)
    ==23889==    by 0x741DCA4: g_thread_pool_thread_proxy (gthreadpool.c:307)
    ==23889==    by 0x741D2C7: g_thread_proxy (gthread.c:780)
    ==23889==    by 0x7C7F6C9: start_thread (in /usr/lib64/libpthread-2.23.90.so)
    ==23889==    by 0x7F9CCCE: clone (in /usr/lib64/libc-2.23.90.so)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766271

 src/file-data.c |    9 ++++++---
 src/file-data.h |    2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/file-data.c b/src/file-data.c
index 0d19519..836554f 100644
--- a/src/file-data.c
+++ b/src/file-data.c
@@ -54,6 +54,7 @@ file_data_free (FileData *fdata)
        g_free (fdata->full_path);
        g_free (fdata->name);
        g_free (fdata->path);
+       g_free (fdata->content_type);
        g_free (fdata->link);
        g_free (fdata->list_name);
        g_free (fdata->sort_key);
@@ -77,7 +78,7 @@ file_data_copy (FileData *src)
        fdata->modified = src->modified;
        fdata->name = g_strdup (src->name);
        fdata->path = g_strdup (src->path);
-       fdata->content_type = src->content_type;
+       fdata->content_type = g_strdup (src->content_type);
        fdata->encrypted = src->encrypted;
        fdata->dir = src->dir;
        fdata->dir_size = src->dir_size;
@@ -93,10 +94,12 @@ file_data_copy (FileData *src)
 void
 file_data_update_content_type (FileData *fdata)
 {
+       g_free (fdata->content_type);
+
        if (fdata->dir)
-               fdata->content_type = MIME_TYPE_DIRECTORY;
+               fdata->content_type = g_strdup (MIME_TYPE_DIRECTORY);
        else
-               fdata->content_type = _g_str_get_static (g_content_type_guess (fdata->full_path, NULL, 0, 
NULL));
+               fdata->content_type = g_content_type_guess (fdata->full_path, NULL, 0, NULL);
 }
 
 
diff --git a/src/file-data.h b/src/file-data.h
index c1bc471..f1440c5 100644
--- a/src/file-data.h
+++ b/src/file-data.h
@@ -38,7 +38,7 @@ typedef struct {
        gboolean    encrypted;        /* Whether the file is encrypted. */
        gboolean    dir;              /* Whether this is a directory listed in the archive */
        goffset     dir_size;
-       const char *content_type;
+       char       *content_type;
 
        /* Additional data. */
 


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