提交 6f2c50e7 编写于 作者: J John Bowler 提交者: Glenn Randers-Pehrson

[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.
上级 c9720568
...@@ -5057,6 +5057,9 @@ Version 1.6.15beta05 [November 5, 2014] ...@@ -5057,6 +5057,9 @@ Version 1.6.15beta05 [November 5, 2014]
seem to generate warnings when an unsigned value is implicitly seem to generate warnings when an unsigned value is implicitly
converted to double. This is probably a GCC bug but this change converted to double. This is probably a GCC bug but this change
avoids the issue by explicitly converting to (int) where safe. 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 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit
......
...@@ -337,6 +337,9 @@ validate_T(void) ...@@ -337,6 +337,9 @@ validate_T(void)
* In both cases the file data is held in a linked list of buffers - not all * In both cases the file data is held in a linked list of buffers - not all
* of these are in use at any time. * 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
{ {
struct buffer_list *next; /* next buffer in list */ struct buffer_list *next; /* next buffer in list */
...@@ -361,6 +364,25 @@ buffer_init(struct buffer *buffer) ...@@ -361,6 +364,25 @@ buffer_init(struct buffer *buffer)
buffer->current = NULL; 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 #ifdef PNG_WRITE_SUPPORTED
static void static void
buffer_start_write(struct buffer *buffer) buffer_start_write(struct buffer *buffer)
...@@ -390,8 +412,6 @@ get_buffer(png_structp pp) ...@@ -390,8 +412,6 @@ get_buffer(png_structp pp)
return (struct buffer*)png_get_io_ptr(pp); return (struct buffer*)png_get_io_ptr(pp);
} }
#define NEW(type) ((type *)malloc(sizeof (type)))
static struct buffer_list * static struct buffer_list *
buffer_extend(struct buffer_list *current) buffer_extend(struct buffer_list *current)
{ {
...@@ -598,6 +618,17 @@ display_clean(struct display *dp) ...@@ -598,6 +618,17 @@ display_clean(struct display *dp)
dp->results = 0; /* reset for next time */ 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 * static struct display *
get_dp(png_structp pp) get_dp(png_structp pp)
/* The display pointer is always stored in the png_struct error pointer */ /* 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) ...@@ -1605,6 +1636,9 @@ main(const int argc, const char * const * const argv)
display_clean(&d); display_clean(&d);
} }
/* Release allocated memory */
display_destroy(&d);
return errors != 0; return errors != 0;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册