[gcab] trivial: Fix a tiny memory leak in CDATA parsing



commit a15d91073fd5d6be258f582dea5d76b92b372a88
Author: Richard Hughes <richard hughsie com>
Date:   Mon Dec 18 12:28:21 2017 +0000

    trivial: Fix a tiny memory leak in CDATA parsing
    
    This only happens when the cab file has the flags _RESERVE_HEADER and the
    file is larger than one CFDATA block in size.

 libgcab/cabinet.c     |    2 +-
 libgcab/gcab-folder.c |    4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c
index b5b44cd..dbea962 100644
--- a/libgcab/cabinet.c
+++ b/libgcab/cabinet.c
@@ -510,6 +510,7 @@ cdata_free (cdata_t *cd)
             z->opaque = NULL;
         }
     }
+    g_free (cd->reserved);
     g_free (cd);
 }
 
@@ -546,7 +547,6 @@ cdata_read (cdata_t *cd, guint8 res_data, gint comptype,
     R4 (cd->checksum);
     R2 (cd->ncbytes);
     R2 (cd->nubytes);
-    cd->reserved = g_malloc (res_data);
     RN (cd->reserved, res_data);
     RN (buf, cd->ncbytes);
 
diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c
index 146bb2e..be3459d 100644
--- a/libgcab/gcab-folder.c
+++ b/libgcab/gcab-folder.c
@@ -434,6 +434,9 @@ gcab_folder_extract (GCabFolder *self,
 
     files = g_slist_sort (g_slist_copy (self->files), (GCompareFunc)sort_by_offset);
 
+    /* this is allocated for every block, but currently unused */
+    cdata->reserved = g_malloc (res_data);
+
     for (f = files; f != NULL; f = f->next) {
         GCabFile *file = f->data;
 
@@ -453,7 +456,6 @@ gcab_folder_extract (GCabFolder *self,
             if (!g_seekable_seek (G_SEEKABLE (data), self->cfolder->offsetdata,
                                   G_SEEK_SET, cancellable, error))
                 return FALSE;
-            bzero(cdata, sizeof(cdata_t));
             nubytes = 0;
         }
 


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