aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/bz2_archive_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-12-31 10:02:55 +0100
committerMax Kellermann <max@duempel.org>2009-12-31 18:27:35 +0100
commitaad05fd1386442330ecc0a15b86cf8081ea47c83 (patch)
tree66e9063f50b1c78cb8dda928e511f84f02f95891 /src/archive/bz2_archive_plugin.c
parent032c5376ad0ad8dca135d210363ef8e454e11167 (diff)
downloadmpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.tar.gz
mpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.tar.xz
mpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.zip
archive: use reference counting for archive+input
Make the input_stream implementation hold a reference on the archive_file object. Allow the caller to "close" the archive_file object immediately, no matter if the open_stream() method has succeeded or not.
Diffstat (limited to '')
-rw-r--r--src/archive/bz2_archive_plugin.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/archive/bz2_archive_plugin.c b/src/archive/bz2_archive_plugin.c
index 975fd3f07..e4a5c3664 100644
--- a/src/archive/bz2_archive_plugin.c
+++ b/src/archive/bz2_archive_plugin.c
@@ -25,6 +25,7 @@
#include "archive/bz2_archive_plugin.h"
#include "archive_api.h"
#include "input_plugin.h"
+#include "refcount.h"
#include <stdint.h>
#include <stddef.h>
@@ -40,6 +41,8 @@
struct bz2_archive_file {
struct archive_file base;
+ struct refcount ref;
+
char *name;
bool reset;
struct input_stream istream;
@@ -105,6 +108,7 @@ bz2_open(const char *pathname, GError **error_r)
context = g_malloc(sizeof(*context));
archive_file_init(&context->base, &bz2_archive_plugin);
+ refcount_init(&context->ref);
//open archive
if (!input_stream_open(&context->istream, pathname, error_r)) {
@@ -149,6 +153,9 @@ bz2_close(struct archive_file *file)
{
struct bz2_archive_file *context = (struct bz2_archive_file *) file;
+ if (!refcount_dec(&context->ref))
+ return;
+
g_free(context->name);
input_stream_close(&context->istream);
@@ -180,6 +187,8 @@ bz2_open_stream(struct archive_file *file, struct input_stream *is,
bis->eof = false;
+ refcount_inc(&context->ref);
+
return true;
}