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/bz2_archive_plugin.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/archive/bz2_archive_plugin.c') 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 #include @@ -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; } -- cgit v1.2.3