[libpng16] Free all allocated memory in pngimage. The file buffer cache was left
allocated at the end of the program, harmless but it causes memory leak reports from clang.
This commit is contained in:
parent
c9720568d0
commit
6f2c50e7fc
3
CHANGES
3
CHANGES
@ -5057,6 +5057,9 @@ Version 1.6.15beta05 [November 5, 2014]
|
||||
seem to generate warnings when an unsigned value is implicitly
|
||||
converted to double. This is probably a GCC bug but this change
|
||||
avoids the issue by explicitly converting to (int) where safe.
|
||||
Free all allocated memory in pngimage. The file buffer cache was left
|
||||
allocated at the end of the program, harmless but it causes memory
|
||||
leak reports from clang.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
@ -337,6 +337,9 @@ validate_T(void)
|
||||
* In both cases the file data is held in a linked list of buffers - not all
|
||||
* of these are in use at any time.
|
||||
*/
|
||||
#define NEW(type) ((type *)malloc(sizeof (type)))
|
||||
#define DELETE(ptr) (free(ptr))
|
||||
|
||||
struct buffer_list
|
||||
{
|
||||
struct buffer_list *next; /* next buffer in list */
|
||||
@ -361,6 +364,25 @@ buffer_init(struct buffer *buffer)
|
||||
buffer->current = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
buffer_destroy_list(struct buffer_list *list)
|
||||
{
|
||||
if (list != NULL)
|
||||
{
|
||||
struct buffer_list *next = list->next;
|
||||
DELETE(list);
|
||||
buffer_destroy_list(next);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
buffer_destroy(struct buffer *buffer)
|
||||
{
|
||||
struct buffer_list *list = buffer->first.next;
|
||||
buffer_init(buffer);
|
||||
buffer_destroy_list(list);
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
static void
|
||||
buffer_start_write(struct buffer *buffer)
|
||||
@ -390,8 +412,6 @@ get_buffer(png_structp pp)
|
||||
return (struct buffer*)png_get_io_ptr(pp);
|
||||
}
|
||||
|
||||
#define NEW(type) ((type *)malloc(sizeof (type)))
|
||||
|
||||
static struct buffer_list *
|
||||
buffer_extend(struct buffer_list *current)
|
||||
{
|
||||
@ -598,6 +618,17 @@ display_clean(struct display *dp)
|
||||
dp->results = 0; /* reset for next time */
|
||||
}
|
||||
|
||||
static void
|
||||
display_destroy(struct display *dp)
|
||||
{
|
||||
/* Release any memory held in the display. */
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
buffer_destroy(&dp->written_file);
|
||||
# endif
|
||||
|
||||
buffer_destroy(&dp->original_file);
|
||||
}
|
||||
|
||||
static struct display *
|
||||
get_dp(png_structp pp)
|
||||
/* The display pointer is always stored in the png_struct error pointer */
|
||||
@ -1605,6 +1636,9 @@ main(const int argc, const char * const * const argv)
|
||||
display_clean(&d);
|
||||
}
|
||||
|
||||
/* Release allocated memory */
|
||||
display_destroy(&d);
|
||||
|
||||
return errors != 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user