aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/iso9660_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/iso9660_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/iso9660_archive_plugin.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/archive/iso9660_archive_plugin.c b/src/archive/iso9660_archive_plugin.c
index 3d5f33896..0d32b9b1b 100644
--- a/src/archive/iso9660_archive_plugin.c
+++ b/src/archive/iso9660_archive_plugin.c
@@ -25,6 +25,7 @@
#include "archive/iso9660_archive_plugin.h"
#include "archive_api.h"
#include "input_plugin.h"
+#include "refcount.h"
#include <cdio/cdio.h>
#include <cdio/iso9660.h>
@@ -37,6 +38,8 @@
struct iso9660_archive_file {
struct archive_file base;
+ struct refcount ref;
+
iso9660_t *iso;
GSList *list;
GSList *iter;
@@ -93,6 +96,7 @@ iso9660_archive_open(const char *pathname, GError **error_r)
g_new(struct iso9660_archive_file, 1);
archive_file_init(&context->base, &iso9660_archive_plugin);
+ refcount_init(&context->ref);
context->list = NULL;
@@ -139,8 +143,11 @@ iso9660_archive_close(struct archive_file *file)
{
struct iso9660_archive_file *context =
(struct iso9660_archive_file *)file;
-
GSList *tmp;
+
+ if (!refcount_dec(&context->ref))
+ return;
+
if (context->list) {
//free list
for (tmp = context->list; tmp != NULL; tmp = g_slist_next(tmp))
@@ -192,6 +199,9 @@ iso9660_archive_open_stream(struct archive_file *file, struct input_stream *is,
is->size = iis->statbuf->size;
iis->max_blocks = CEILING(iis->statbuf->size, ISO_BLOCKSIZE);
+
+ refcount_inc(&context->ref);
+
return true;
}