Merge "Add EndIteration method to free memory allocated"

This commit is contained in:
Piotr Jastrzebski 2014-08-11 09:49:59 +00:00 committed by Gerrit Code Review
commit 400e73720c
2 changed files with 16 additions and 4 deletions

View file

@ -130,10 +130,10 @@ int32_t FindEntry(const ZipArchiveHandle handle, const char* entryName,
/* /*
* Start iterating over all entries of a zip file. The order of iteration * Start iterating over all entries of a zip file. The order of iteration
* is not guaranteed to be the same as the order of elements * is not guaranteed to be the same as the order of elements
* in the central directory but is stable for a given zip file. |cookie| * in the central directory but is stable for a given zip file. |cookie| will
* must point to a writeable memory location, and will be set to the value * contain the value of an opaque cookie which can be used to make one or more
* of an opaque cookie which can be used to make one or more calls to * calls to Next. All calls to StartIteration must be matched by a call to
* Next. * EndIteration to free any allocated memory.
* *
* This method also accepts an optional prefix to restrict iteration to * This method also accepts an optional prefix to restrict iteration to
* entry names that start with |prefix|. * entry names that start with |prefix|.
@ -151,6 +151,12 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr,
*/ */
int32_t Next(void* cookie, ZipEntry* data, ZipEntryName *name); int32_t Next(void* cookie, ZipEntry* data, ZipEntryName *name);
/*
* End iteration over all entries of a zip file and frees the memory allocated
* in StartIteration.
*/
void EndIteration(void* cookie);
/* /*
* Uncompress and write an entry to an open file identified by |fd|. * Uncompress and write an entry to an open file identified by |fd|.
* |entry->uncompressed_length| bytes will be written to the file at * |entry->uncompressed_length| bytes will be written to the file at

View file

@ -909,6 +909,12 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const char* p
return 0; return 0;
} }
void EndIteration(void* cookie) {
if (cookie != NULL) {
free(cookie);
}
}
int32_t FindEntry(const ZipArchiveHandle handle, const char* entryName, int32_t FindEntry(const ZipArchiveHandle handle, const char* entryName,
ZipEntry* data) { ZipEntry* data) {
const ZipArchive* archive = (ZipArchive*) handle; const ZipArchive* archive = (ZipArchive*) handle;