From ae004b1bfc17fdb492d7d1ff8965d37ce6467071 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Thu, 7 Feb 2008 12:31:09 +0100 Subject: [PATCH] Allow to use NULL as free function for image attached data. --- libisofs/image.c | 15 +++++++++------ libisofs/libisofs.h | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libisofs/image.c b/libisofs/image.c index 0792483..4539ac9 100644 --- a/libisofs/image.c +++ b/libisofs/image.c @@ -94,7 +94,7 @@ void iso_image_unref(IsoImage *image) int nexcl; /* we need to free the image */ - if (image->user_data != NULL) { + if (image->user_data_free != NULL) { /* free attached data */ image->user_data_free(image->user_data); } @@ -129,12 +129,12 @@ void iso_image_unref(IsoImage *image) * @param data * Pointer to application defined data that will be attached to the * image. You can pass NULL to remove any already attached data. - * @param free + * @param give_up * Function that will be called when the image does not need the data * any more. It receives the data pointer as an argumente, and eventually - * causes data to be free. + * causes data to be free. It can be NULL if you don't need it. */ -int iso_image_attach_data(IsoImage *image, void *data, void (*free)(void*)) +int iso_image_attach_data(IsoImage *image, void *data, void (*give_up)(void*)) { if (image == NULL || (data != NULL && free == NULL)) { return ISO_NULL_POINTER; @@ -142,13 +142,16 @@ int iso_image_attach_data(IsoImage *image, void *data, void (*free)(void*)) if (image->user_data != NULL) { /* free previously attached data */ - image->user_data_free(image->user_data); + if (image->user_data_free) { + image->user_data_free(image->user_data); + } image->user_data = NULL; + image->user_data_free = NULL; } if (data != NULL) { image->user_data = data; - image->user_data_free = free; + image->user_data_free = give_up; } return ISO_SUCCESS; } diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 30e6930..f8ef19b 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -1344,16 +1344,16 @@ void iso_image_unref(IsoImage *image); * @param data * Pointer to application defined data that will be attached to the * image. You can pass NULL to remove any already attached data. - * @param free + * @param give_up * Function that will be called when the image does not need the data * any more. It receives the data pointer as an argumente, and eventually - * causes data to be free. + * causes data to be freed. It can be NULL if you don't need it. * @return * 1 on succes, < 0 on error * * @since 0.6.2 */ -int iso_image_attach_data(IsoImage *image, void *data, void (*free)(void*)); +int iso_image_attach_data(IsoImage *image, void *data, void (*give_up)(void*)); /** * The the data previously attached with iso_image_attach_data()