|
|
a3a8ff |
From 35ae4edd9a6abef11fbdbfef5e717ba6eee6f8ee Mon Sep 17 00:00:00 2001
|
|
|
a3a8ff |
From: Patrick Uiterwijk <puiterwijk@redhat.com>
|
|
|
a3a8ff |
Date: Wed, 28 Sep 2016 12:09:07 +0000
|
|
|
a3a8ff |
Subject: [PATCH] Close BZ2 compressed files on cr_close
|
|
|
a3a8ff |
|
|
|
a3a8ff |
Per bzip2 documentation: "BZ2_bzReadClose does not call fclose on the underlying file
|
|
|
a3a8ff |
handle, so you should do that yourself if appropriate.".
|
|
|
a3a8ff |
This patch adds a INNERFILE element to CR_FILE to keep track of the FILE object so we
|
|
|
a3a8ff |
can properly close the file on cr_close.
|
|
|
a3a8ff |
|
|
|
a3a8ff |
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
|
|
|
a3a8ff |
---
|
|
|
a3a8ff |
src/compression_wrapper.c | 6 ++++++
|
|
|
a3a8ff |
src/compression_wrapper.h | 1 +
|
|
|
a3a8ff |
2 files changed, 7 insertions(+)
|
|
|
a3a8ff |
|
|
|
a3a8ff |
diff --git a/src/compression_wrapper.c b/src/compression_wrapper.c
|
|
|
a3a8ff |
index aacaf90..adc2f39 100644
|
|
|
a3a8ff |
--- a/src/compression_wrapper.c
|
|
|
a3a8ff |
+++ b/src/compression_wrapper.c
|
|
|
a3a8ff |
@@ -347,6 +347,7 @@ cr_sopen(const char *filename,
|
|
|
a3a8ff |
file = g_malloc0(sizeof(CR_FILE));
|
|
|
a3a8ff |
file->mode = mode;
|
|
|
a3a8ff |
file->type = type;
|
|
|
a3a8ff |
+ file->INNERFILE = NULL;
|
|
|
a3a8ff |
|
|
|
a3a8ff |
switch (type) {
|
|
|
a3a8ff |
|
|
|
a3a8ff |
@@ -380,6 +381,7 @@ cr_sopen(const char *filename,
|
|
|
a3a8ff |
|
|
|
a3a8ff |
case (CR_CW_BZ2_COMPRESSION): { // ------------------------------------
|
|
|
a3a8ff |
FILE *f = fopen(filename, mode_str);
|
|
|
a3a8ff |
+ file->INNERFILE = f;
|
|
|
a3a8ff |
int bzerror;
|
|
|
a3a8ff |
|
|
|
a3a8ff |
if (!f) {
|
|
|
a3a8ff |
@@ -405,6 +407,8 @@ cr_sopen(const char *filename,
|
|
|
a3a8ff |
if (bzerror != BZ_OK) {
|
|
|
a3a8ff |
const char *err_msg;
|
|
|
a3a8ff |
|
|
|
a3a8ff |
+ fclose(f);
|
|
|
a3a8ff |
+
|
|
|
a3a8ff |
switch (bzerror) {
|
|
|
a3a8ff |
case BZ_CONFIG_ERROR:
|
|
|
a3a8ff |
err_msg = "library has been mis-compiled";
|
|
|
a3a8ff |
@@ -642,6 +646,8 @@ cr_close(CR_FILE *cr_file, GError **err)
|
|
|
a3a8ff |
BZ2_bzWriteClose(&rc, (BZFILE *) cr_file->FILE,
|
|
|
a3a8ff |
BZ2_SKIP_FFLUSH, NULL, NULL);
|
|
|
a3a8ff |
|
|
|
a3a8ff |
+ fclose(cr_file->INNERFILE);
|
|
|
a3a8ff |
+
|
|
|
a3a8ff |
if (rc == BZ_OK) {
|
|
|
a3a8ff |
ret = CRE_OK;
|
|
|
a3a8ff |
} else {
|
|
|
a3a8ff |
diff --git a/src/compression_wrapper.h b/src/compression_wrapper.h
|
|
|
a3a8ff |
index 910fd45..65022d9 100644
|
|
|
a3a8ff |
--- a/src/compression_wrapper.h
|
|
|
a3a8ff |
+++ b/src/compression_wrapper.h
|
|
|
a3a8ff |
@@ -79,6 +79,7 @@ void cr_contentstat_free(cr_ContentStat *cstat, GError **err);
|
|
|
a3a8ff |
typedef struct {
|
|
|
a3a8ff |
cr_CompressionType type; /*!< Type of compression */
|
|
|
a3a8ff |
void *FILE; /*!< Pointer to gzFile, BZFILE, ... */
|
|
|
a3a8ff |
+ void *INNERFILE; /*!< Pointer to underlying FILE */
|
|
|
a3a8ff |
cr_OpenMode mode; /*!< Mode */
|
|
|
a3a8ff |
cr_ContentStat *stat; /*!< Content stats */
|
|
|
a3a8ff |
cr_ChecksumCtx *checksum_ctx; /*!< Checksum contenxt */
|