png_data_freer -- change the default behavior for freeing data


#include <png.h>

void png_data_freer(png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask);


This interface shall change the default behavior for freeing allocated data, from only freeing data allocated internally by libpng, to either freeing user-allocated data or to not freeing any data at all.

This interface can enable deallocation of user data allocated with png_malloc() or png_zalloc() and passed to libpng with one of the png_set_*() interfaces. Users can call it both before and after passing the data. Calling it after reading PNG data but before passing the data controls whether the user or the interface is responsible for the existing data. Calling it after passing the data controls whether the user or the interface should deallocate the data.

If the user becomes responsible for data allocated by libpng, png_free() must be called to free it. If libpng becomes responsible for user-allocated data, the data must only have been allocated with png_malloc() or png_zalloc().

The parameter png_ptr shall specify the PNG file.

The parameter info_ptr shall specify the PNG info structure.

The parameter freer shall specify one of these constants: PNG_DESTROY_WILL_FREE_DATA, PNG_SET_WILL_FREE_DATA, PNG_USER_WILL_FREE_DATA.

The parameter mask shall specify the data to free, as described under png_free_data().

Application Usage (informative)

A row_pointers array allocated in a single block must not be freed with png_set_rows() or png_read_destroy(), because they would attempt to free the elements of the array as well.

Do not free text_ptr with libpng if some of its members were allocated separately, because this will actually only free text_ptr.key. If responsibility for freeing text_ptr moves from libpng to the user, the user must not free the members separately.