From aad05fd1386442330ecc0a15b86cf8081ea47c83 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 31 Dec 2009 10:02:55 +0100 Subject: 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. --- src/archive/iso9660_archive_plugin.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/archive/iso9660_archive_plugin.c') 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 #include @@ -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; } -- cgit v1.2.3