List Archive

Thread

Thread Index

Message

From: Dieter Baron <dillo%nih.at@localhost>
To: Andreas Falkenhahn <andreas%falkenhahn.com@localhost>
Subject: Re: When to free zip_source?
Date: Wed, 1 Nov 2017 10:23:32 +0100



On 31.10.2017, at 16:06 , Andreas Falkenhahn <andreas%falkenhahn.com@localhost> wrote:


I want to add a file to a zip archive from custom data streamed in using
a callback source, like so:

s = zip_source_function(arc->archive, my_zip_source_callback, userdata);
zip_file_add(arc->archive, name, s, ZIP_FL_ENC_UTF_8);

Now when should I free "s"? I cannot do this right after zip_file_add() because
the source is still needed. So do I have to do it after

zip_close(arc->archive);

?

No, zip_file_add transfers ownership of my_zip_source to libzip. It will be freed when libzip no longer needs it.

See also this paragraph from zip_source_free(3):

NOTE: This function should not be called on a source after it was used successfully in a zip_open_from_source(3)zip_file_add(3), or zip_file_replace(3) call.

Yes. We should probably add a similar paragraph to the man pages for zip_file_add() and zip_file_replaece().


Or are sources freed automatically when closing an archive?

Yes.


Or are they freed
automatically on ZIP_SOURCE_FREE? The documentation on ZIP_SOURCE_FREE says:

ZIP_SOURCE_FREE: Clean up and free all resources, including `state`. The
                       callback function will not be called again.

What is meant by "state" here? Does this mean the source will be freed
automatically?

state should read userdata, I’ve fixed it in the man page.

When a source is freed with zip_source_free(), it’s callback is called with the command ZIP_SOURCE_FREE.

yours,
dillo


Tks

--
Best regards,
Andreas Falkenhahn                          mailto:andreas%falkenhahn.com@localhost

Made by MHonArc.