The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly.



writepng_cleanup()

The last tasks for the main program are to clean up the PNG-specific allocations and the main-program-specific ones, which is accomplished via the writepng_cleanup() and wpng_cleanup() functions. The former is very similar to the analogous routine in Chapter 14, "Reading PNG Images Progressively", except that this one calls png_destroy_write_struct(), which has only two arguments:

void writepng_cleanup(mainprog_info *mainprog_ptr)
{
    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;

    if (png_ptr && info_ptr)
        png_destroy_write_struct(&png_ptr, &info_ptr);
}

wpng_cleanup() closes both input and output files and frees the image_data and row_pointers arrays, assuming they were allocated. Since both cleanup functions are also called as a result of various error conditions, they check for valid pointers before freeing anything and set NULL pointers for anything they do free.




Last Update: 2010-Nov-26