[gcab] cabinet: free zlib after usage



commit c2a5715419abb931e1d2c1ee7f6e83d71abd7b88
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Fri Jan 18 01:32:38 2013 +0100

    cabinet: free zlib after usage

 libgcab/cabinet.c     |   15 +++++++++++++--
 libgcab/cabinet.h     |    2 +-
 libgcab/gcab-folder.c |    3 ++-
 3 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c
index b38c0b9..7bf609e 100644
--- a/libgcab/cabinet.c
+++ b/libgcab/cabinet.c
@@ -402,9 +402,20 @@ cdata_write (cdata_t *cd, GDataOutputStream *out, int type,
 }
 
 G_GNUC_INTERNAL void
-cdata_finish (cdata_t *cd)
+cdata_finish (cdata_t *cd, GError **error)
 {
+    z_stream *z = &cd->z;
+    int zret;
 
+    if (!z->opaque)
+        return;
+
+    zret = inflateEnd (z);
+    z->opaque = NULL;
+
+    if (zret != Z_OK)
+        g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
+                     "zlib failed: %s", zError (zret));
 }
 
 G_GNUC_INTERNAL gboolean
@@ -485,7 +496,7 @@ cdata_read (cdata_t *cd, u1 res_data, GCabCompression compression,
 end:
     if (zret != Z_OK)
         g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
-                     "zlib failed: %s", zError(zret));
+                     "zlib failed: %s", zError (zret));
     if (!*error && !success)
         g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
                      "Invalid cabint chunk");
diff --git a/libgcab/cabinet.h b/libgcab/cabinet.h
index c7ea983..b7e8fb3 100644
--- a/libgcab/cabinet.h
+++ b/libgcab/cabinet.h
@@ -138,6 +138,6 @@ gboolean     cdata_read                         (cdata_t *cd,
                                                  GDataInputStream *in,
                                                  GCancellable *cancellable,
                                                  GError **error);
-void         cdata_finish                       (cdata_t *cd);
+void         cdata_finish                       (cdata_t *cd, GError **error);
 
 #endif /* CABINET_H */
diff --git a/libgcab/gcab-folder.c b/libgcab/gcab-folder.c
index f9c7f0f..4113d50 100644
--- a/libgcab/gcab-folder.c
+++ b/libgcab/gcab-folder.c
@@ -377,7 +377,8 @@ end:
         g_object_unref (data);
     if (out)
         g_object_unref (out);
-    cdata_finish (&cdata);
+
+    cdata_finish (&cdata, NULL);
 
     return success;
 }



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