blob: eca9a2cbda99685e17bc73145a2adc65e0877d21 [file] [log] [blame]
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001
Guy Schalnat0f716451995-11-28 11:22:13 -06002/* pngmem.c - stub functions for memory allocation
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrson668af4e2009-06-24 06:35:59 -05004 * Last changed in libpng 1.4.0 [June 24, 2009]
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -06005 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05006 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06008 *
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -05009 * This code is released under the zlib-libpng license.
10 * For conditions of distribution and use, see copyright notice in png.h
11 *
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -050012 * This file provides a location for all memory allocation. Users who
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -050013 * need special memory handling are expected to supply replacement
14 * functions for png_malloc() and png_free(), and to use
15 * png_create_read_struct_2() and png_create_write_struct_2() to
16 * identify the replacement functions.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060017 */
Guy Schalnat0d580581995-07-20 02:43:20 -050018
Guy Schalnat0d580581995-07-20 02:43:20 -050019#include "png.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060020#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050021#include "pngpriv.h"
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -060022
Guy Schalnat4ee97b01996-01-16 01:51:56 -060023/* Borland DOS special memory handler */
24#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -050025/* If you change this, be sure to change the one in png.h also */
Guy Schalnat4ee97b01996-01-16 01:51:56 -060026
Guy Schalnate5a37791996-06-05 15:50:50 -050027/* Allocate memory for a png_struct. The malloc and memset can be replaced
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060028 by a single call to calloc() if this is thought to improve performance. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050029png_voidp /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060030png_create_struct(int type)
Guy Schalnate5a37791996-06-05 15:50:50 -050031{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050032#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050033 return (png_create_struct_2(type, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050034}
35
36/* Alternate version of png_create_struct, for use with user-defined malloc. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050037png_voidp /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050038png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050039{
40#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -060041 png_size_t size;
Guy Schalnate5a37791996-06-05 15:50:50 -050042 png_voidp struct_ptr;
43
44 if (type == PNG_STRUCT_INFO)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050045 size = png_sizeof(png_info);
Guy Schalnate5a37791996-06-05 15:50:50 -050046 else if (type == PNG_STRUCT_PNG)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050047 size = png_sizeof(png_struct);
Guy Schalnate5a37791996-06-05 15:50:50 -050048 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050049 return (png_get_copyright(NULL));
Guy Schalnate5a37791996-06-05 15:50:50 -050050
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050051#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050052 if (malloc_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050053 {
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050054 png_struct dummy_struct;
55 png_structp png_ptr = &dummy_struct;
56 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050057 struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050058 }
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050059 else
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050060#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -050061 struct_ptr = (png_voidp)farmalloc(size);
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -050062 if (struct_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -050063 png_memset(struct_ptr, 0, size);
Guy Schalnate5a37791996-06-05 15:50:50 -050064 return (struct_ptr);
65}
66
Guy Schalnate5a37791996-06-05 15:50:50 -050067/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050068void /* PRIVATE */
Guy Schalnate5a37791996-06-05 15:50:50 -050069png_destroy_struct(png_voidp struct_ptr)
70{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050071#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -050072 png_destroy_struct_2(struct_ptr, NULL, NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050073}
74
75/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -050076void /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050077png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
78 png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050079{
80#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050081 if (struct_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060082 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050083#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -050084 if (free_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050085 {
86 png_struct dummy_struct;
87 png_structp png_ptr = &dummy_struct;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -050088 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050089 (*(free_fn))(png_ptr, struct_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050090 return;
91 }
92#endif /* PNG_USER_MEM_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -050093 farfree (struct_ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -060094 }
Guy Schalnate5a37791996-06-05 15:50:50 -050095}
96
Guy Schalnat0d580581995-07-20 02:43:20 -050097/* Allocate memory. For reasonable files, size should never exceed
Andreas Dilger47a0c421997-05-16 02:46:07 -050098 * 64K. However, zlib may allocate more then 64K if you don't tell
99 * it not to. See zconf.h and png.h for more information. zlib does
100 * need to allocate exactly 64K, so whatever you call here must
101 * have the ability to do that.
102 *
103 * Borland seems to have a problem in DOS mode for exactly 64K.
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500104 * It gives you a segment with an offset of 8 (perhaps to store its
Andreas Dilger47a0c421997-05-16 02:46:07 -0500105 * memory stuff). zlib doesn't like this at all, so we have to
106 * detect and deal with it. This code should not be needed in
107 * Windows or OS/2 modes, and only in 16 bit mode. This code has
108 * been updated by Alexander Lehmann for version 0.89 to waste less
109 * memory.
110 *
111 * Note that we can't use png_size_t for the "size" declaration,
112 * since on some systems a png_size_t is a 16-bit quantity, and as a
113 * result, we would be truncating potentially larger memory requests
114 * (which should cause a fatal error) and introducing major problems.
115 */
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600116#ifdef PNG_CALLOC_SUPPORTED
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500117png_voidp PNGAPI
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600118png_calloc(png_structp png_ptr, png_alloc_size_t size)
119{
120 png_voidp ret;
121
122 ret = (png_malloc(png_ptr, size));
123 if (ret != NULL)
124 png_memset(ret,0,(png_size_t)size);
125 return (ret);
126}
Glenn Randers-Pehrson0ffb71a2009-02-28 06:08:20 -0600127#endif
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600128
129png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500130png_malloc(png_structp png_ptr, png_alloc_size_t size)
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600131{
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600132 png_voidp ret;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500133
Andreas Dilger47a0c421997-05-16 02:46:07 -0500134 if (png_ptr == NULL || size == 0)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500135 return (NULL);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600136
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500137#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500138 if (png_ptr->malloc_fn != NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500139 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500140 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500141 ret = (png_malloc_default(png_ptr, size));
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500142 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500143 png_error(png_ptr, "Out of memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500144 return (ret);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500145}
146
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500147png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500148png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500149{
150 png_voidp ret;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600151#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500152
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600153 if (png_ptr == NULL || size == 0)
154 return (NULL);
155
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600156#ifdef PNG_MAX_MALLOC_64K
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500157 if (size > (png_uint_32)65536L)
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500158 {
159 png_warning(png_ptr, "Cannot Allocate > 64K");
160 ret = NULL;
161 }
162 else
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600163#endif
164
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500165 if (size != (size_t)size)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500166 ret = NULL;
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500167 else if (size == (png_uint_32)65536L)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600168 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500169 if (png_ptr->offset_table == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600170 {
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500171 /* Try to see if we need to do any of this fancy stuff */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600172 ret = farmalloc(size);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500173 if (ret == NULL || ((png_size_t)ret & 0xffff))
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600174 {
175 int num_blocks;
176 png_uint_32 total_size;
177 png_bytep table;
178 int i;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600179 png_byte huge * hptr;
180
Andreas Dilger47a0c421997-05-16 02:46:07 -0500181 if (ret != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600182 {
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600183 farfree(ret);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600184 ret = NULL;
185 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600186
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500187 if (png_ptr->zlib_window_bits > 14)
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500188 num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
189 else
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600190 num_blocks = 1;
191 if (png_ptr->zlib_mem_level >= 7)
192 num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
193 else
194 num_blocks++;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600195
Guy Schalnate5a37791996-06-05 15:50:50 -0500196 total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600197
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600198 table = farmalloc(total_size);
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600199
Andreas Dilger47a0c421997-05-16 02:46:07 -0500200 if (table == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600201 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500202#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500203 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500204 png_error(png_ptr, "Out Of Memory"); /* Note "O" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600205 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500206 png_warning(png_ptr, "Out Of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500207#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600208 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600209 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600210
Andreas Dilger47a0c421997-05-16 02:46:07 -0500211 if ((png_size_t)table & 0xfff0)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600212 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500213#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500214 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600215 png_error(png_ptr,
216 "Farmalloc didn't return normalized pointer");
217 else
218 png_warning(png_ptr,
219 "Farmalloc didn't return normalized pointer");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500220#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600221 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600222 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600223
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600224 png_ptr->offset_table = table;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500225 png_ptr->offset_table_ptr = farmalloc(num_blocks *
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500226 png_sizeof(png_bytep));
Guy Schalnate5a37791996-06-05 15:50:50 -0500227
Andreas Dilger47a0c421997-05-16 02:46:07 -0500228 if (png_ptr->offset_table_ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600229 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500230#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500231 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500232 png_error(png_ptr, "Out Of memory"); /* Note "O" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600233 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500234 png_warning(png_ptr, "Out Of memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500235#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600236 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500237 }
238
239 hptr = (png_byte huge *)table;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500240 if ((png_size_t)hptr & 0xf)
Guy Schalnate5a37791996-06-05 15:50:50 -0500241 {
242 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500243 hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600244 }
245 for (i = 0; i < num_blocks; i++)
246 {
247 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500248 hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600249 }
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600250
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600251 png_ptr->offset_table_number = num_blocks;
252 png_ptr->offset_table_count = 0;
253 png_ptr->offset_table_count_free = 0;
254 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600255 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500256
257 if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600258 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500259#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500260 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500261 png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600262 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500263 png_warning(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500264#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600265 return (NULL);
266 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500267
268 ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600269 }
270 else
271 ret = farmalloc(size);
Guy Schalnat0d580581995-07-20 02:43:20 -0500272
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500273#ifndef PNG_USER_MEM_SUPPORTED
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500274 if (ret == NULL)
Guy Schalnat0d580581995-07-20 02:43:20 -0500275 {
Glenn Randers-Pehrson5b5dcf82004-07-17 22:45:44 -0500276 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500277 png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600278 else
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500279 png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
Guy Schalnat0d580581995-07-20 02:43:20 -0500280 }
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500281#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500282
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600283 return (ret);
Guy Schalnat0d580581995-07-20 02:43:20 -0500284}
285
Glenn Randers-Pehrson4bb4d012009-05-20 12:45:29 -0500286/* Free a pointer allocated by png_malloc(). In the default
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500287 * configuration, png_ptr is not used, but is passed in case it
288 * is needed. If ptr is NULL, return without taking any action.
289 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500290void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500291png_free(png_structp png_ptr, png_voidp ptr)
Guy Schalnat0d580581995-07-20 02:43:20 -0500292{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500293 if (png_ptr == NULL || ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600294 return;
295
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500296#ifdef PNG_USER_MEM_SUPPORTED
297 if (png_ptr->free_fn != NULL)
298 {
299 (*(png_ptr->free_fn))(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500300 return;
301 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500302 else
303 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500304}
305
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500306void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500307png_free_default(png_structp png_ptr, png_voidp ptr)
308{
309#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600310
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500311 if (png_ptr == NULL || ptr == NULL)
312 return;
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600313
Andreas Dilger47a0c421997-05-16 02:46:07 -0500314 if (png_ptr->offset_table != NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600315 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500316 int i;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600317
Andreas Dilger47a0c421997-05-16 02:46:07 -0500318 for (i = 0; i < png_ptr->offset_table_count; i++)
319 {
320 if (ptr == png_ptr->offset_table_ptr[i])
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600321 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500322 ptr = NULL;
323 png_ptr->offset_table_count_free++;
324 break;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600325 }
326 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500327 if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
328 {
329 farfree(png_ptr->offset_table);
330 farfree(png_ptr->offset_table_ptr);
331 png_ptr->offset_table = NULL;
332 png_ptr->offset_table_ptr = NULL;
333 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600334 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500335
336 if (ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600337 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500338 farfree(ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600339 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600340}
341
342#else /* Not the Borland DOS special memory handler */
343
Guy Schalnate5a37791996-06-05 15:50:50 -0500344/* Allocate memory for a png_struct or a png_info. The malloc and
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600345 memset can be replaced by a single call to calloc() if this is thought
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500346 to improve performance noticably. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500347png_voidp /* PRIVATE */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600348png_create_struct(int type)
Guy Schalnate5a37791996-06-05 15:50:50 -0500349{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500350#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500351 return (png_create_struct_2(type, NULL, NULL));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500352}
353
354/* Allocate memory for a png_struct or a png_info. The malloc and
355 memset can be replaced by a single call to calloc() if this is thought
Glenn Randers-Pehrsond1e8c862002-06-20 06:54:34 -0500356 to improve performance noticably. */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500357png_voidp /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500358png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500359{
360#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500361 png_size_t size;
Guy Schalnate5a37791996-06-05 15:50:50 -0500362 png_voidp struct_ptr;
363
364 if (type == PNG_STRUCT_INFO)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500365 size = png_sizeof(png_info);
Guy Schalnate5a37791996-06-05 15:50:50 -0500366 else if (type == PNG_STRUCT_PNG)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500367 size = png_sizeof(png_struct);
Guy Schalnate5a37791996-06-05 15:50:50 -0500368 else
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500369 return (NULL);
Guy Schalnate5a37791996-06-05 15:50:50 -0500370
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500371#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500372 if (malloc_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500373 {
Glenn Randers-Pehrson5cded0b2001-11-07 07:10:08 -0600374 png_struct dummy_struct;
375 png_structp png_ptr = &dummy_struct;
376 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonae498dc2001-11-24 14:53:31 -0600377 struct_ptr = (*(malloc_fn))(png_ptr, size);
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500378 if (struct_ptr != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500379 png_memset(struct_ptr, 0, size);
380 return (struct_ptr);
381 }
382#endif /* PNG_USER_MEM_SUPPORTED */
383
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500384#if defined(__TURBOC__) && !defined(__FLAT__)
385 struct_ptr = (png_voidp)farmalloc(size);
386#else
387# if defined(_MSC_VER) && defined(MAXSEG_64K)
388 struct_ptr = (png_voidp)halloc(size, 1);
389# else
390 struct_ptr = (png_voidp)malloc(size);
391# endif
392#endif
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500393 if (struct_ptr != NULL)
Guy Schalnate5a37791996-06-05 15:50:50 -0500394 png_memset(struct_ptr, 0, size);
Guy Schalnate5a37791996-06-05 15:50:50 -0500395
396 return (struct_ptr);
397}
398
399
400/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500401void /* PRIVATE */
Guy Schalnate5a37791996-06-05 15:50:50 -0500402png_destroy_struct(png_voidp struct_ptr)
403{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500404#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500405 png_destroy_struct_2(struct_ptr, NULL, NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500406}
407
408/* Free memory allocated by a png_create_struct() call */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500409void /* PRIVATE */
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500410png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
411 png_voidp mem_ptr)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500412{
413#endif /* PNG_USER_MEM_SUPPORTED */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500414 if (struct_ptr != NULL)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600415 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500416#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500417 if (free_fn != NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500418 {
419 png_struct dummy_struct;
420 png_structp png_ptr = &dummy_struct;
Glenn Randers-Pehrson8b6a8892001-05-18 04:54:50 -0500421 png_ptr->mem_ptr=mem_ptr;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500422 (*(free_fn))(png_ptr, struct_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500423 return;
424 }
425#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500426#if defined(__TURBOC__) && !defined(__FLAT__)
427 farfree(struct_ptr);
428#else
429# if defined(_MSC_VER) && defined(MAXSEG_64K)
430 hfree(struct_ptr);
431# else
432 free(struct_ptr);
433# endif
434#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600435 }
Guy Schalnate5a37791996-06-05 15:50:50 -0500436}
437
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600438/* Allocate memory. For reasonable files, size should never exceed
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500439 * 64K. However, zlib may allocate more then 64K if you don't tell
440 * it not to. See zconf.h and png.h for more information. zlib does
441 * need to allocate exactly 64K, so whatever you call here must
442 * have the ability to do that.
443 */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600444
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500445png_voidp PNGAPI
Glenn Randers-Pehrson79134c62009-02-14 10:32:18 -0600446png_calloc(png_structp png_ptr, png_alloc_size_t size)
447{
448 png_voidp ret;
449
450 ret = (png_malloc(png_ptr, size));
451 if (ret != NULL)
452 png_memset(ret,0,(png_size_t)size);
453 return (ret);
454}
455
456png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500457png_malloc(png_structp png_ptr, png_alloc_size_t size)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600458{
459 png_voidp ret;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500460
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500461#ifdef PNG_USER_MEM_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500462 if (png_ptr == NULL || size == 0)
Glenn Randers-Pehrson3f549252001-10-27 07:35:13 -0500463 return (NULL);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600464
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500465 if (png_ptr->malloc_fn != NULL)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500466 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500467 else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500468 ret = (png_malloc_default(png_ptr, size));
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500469 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500470 png_error(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500471 return (ret);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500472}
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500473
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600474png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500475png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500476{
477 png_voidp ret;
478#endif /* PNG_USER_MEM_SUPPORTED */
479
Glenn Randers-Pehrson272489d2004-08-04 06:34:52 -0500480 if (png_ptr == NULL || size == 0)
481 return (NULL);
482
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600483#ifdef PNG_MAX_MALLOC_64K
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500484 if (size > (png_uint_32)65536L)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600485 {
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500486#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500487 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600488 png_error(png_ptr, "Cannot Allocate > 64K");
489 else
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500490#endif
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600491 return NULL;
492 }
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600493#endif
494
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500495 /* Check for overflow */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500496#if defined(__TURBOC__) && !defined(__FLAT__)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500497 if (size != (unsigned long)size)
498 ret = NULL;
499 else
500 ret = farmalloc(size);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500501#else
502# if defined(_MSC_VER) && defined(MAXSEG_64K)
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500503 if (size != (unsigned long)size)
504 ret = NULL;
505 else
506 ret = halloc(size, 1);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500507# else
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500508 if (size != (size_t)size)
509 ret = NULL;
510 else
511 ret = malloc((size_t)size);
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500512# endif
513#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600514
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500515#ifndef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson9c0f0942002-02-21 23:14:23 -0600516 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600517 png_error(png_ptr, "Out of Memory");
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500518#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600519
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600520 return (ret);
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600521}
522
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500523/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500524 * without taking any action.
525 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500526void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500527png_free(png_structp png_ptr, png_voidp ptr)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600528{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500529 if (png_ptr == NULL || ptr == NULL)
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600530 return;
Guy Schalnat0d580581995-07-20 02:43:20 -0500531
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500532#ifdef PNG_USER_MEM_SUPPORTED
533 if (png_ptr->free_fn != NULL)
534 {
535 (*(png_ptr->free_fn))(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500536 return;
537 }
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500538 else
539 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500540}
Glenn Randers-Pehrson73d57cb2002-03-25 18:49:08 -0600541void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500542png_free_default(png_structp png_ptr, png_voidp ptr)
543{
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500544 if (png_ptr == NULL || ptr == NULL)
545 return;
546
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500547#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500548
549#if defined(__TURBOC__) && !defined(__FLAT__)
550 farfree(ptr);
551#else
552# if defined(_MSC_VER) && defined(MAXSEG_64K)
553 hfree(ptr);
554# else
555 free(ptr);
556# endif
557#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500558}
559
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600560#endif /* Not Borland DOS special memory handler */
Guy Schalnat6d764711995-12-19 03:22:19 -0600561
Glenn Randers-Pehrson2ae022d2002-07-01 22:23:46 -0500562/* This function was added at libpng version 1.2.3. The png_malloc_warn()
Glenn Randers-Pehrson5fea36f2004-07-28 08:20:44 -0500563 * function will set up png_malloc() to issue a png_warning and return NULL
564 * instead of issuing a png_error, if it fails to allocate the requested
565 * memory.
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500566 */
567png_voidp PNGAPI
Glenn Randers-Pehrsonbeb572e2006-08-19 13:59:24 -0500568png_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500569{
570 png_voidp ptr;
Glenn Randers-Pehrsonae4bd5c2006-11-16 20:35:49 -0600571 png_uint_32 save_flags;
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500572 if (png_ptr == NULL)
573 return (NULL);
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500574
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500575 save_flags = png_ptr->flags;
Glenn Randers-Pehrson07748d12002-05-25 11:12:10 -0500576 png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
577 ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
578 png_ptr->flags=save_flags;
579 return(ptr);
580}
581
Glenn Randers-Pehrson145f5c82008-07-10 09:13:13 -0500582
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500583#ifdef PNG_USER_MEM_SUPPORTED
584/* This function is called when the application wants to use another method
585 * of allocating and freeing memory.
586 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500587void PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500588png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
589 malloc_fn, png_free_ptr free_fn)
590{
Glenn Randers-Pehrson895a9c92008-07-25 08:51:18 -0500591 if (png_ptr != NULL)
592 {
593 png_ptr->mem_ptr = mem_ptr;
594 png_ptr->malloc_fn = malloc_fn;
595 png_ptr->free_fn = free_fn;
Glenn Randers-Pehrson6b12c082006-11-14 10:53:30 -0600596 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500597}
598
599/* This function returns a pointer to the mem_ptr associated with the user
600 * functions. The application should free any memory associated with this
601 * pointer before png_write_destroy and png_read_destroy are called.
602 */
Glenn Randers-Pehrson75294572000-05-06 14:09:57 -0500603png_voidp PNGAPI
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500604png_get_mem_ptr(png_structp png_ptr)
605{
Glenn Randers-Pehrson glennrp@comcast.netb1c0d332009-05-15 20:39:34 -0500606 if (png_ptr == NULL)
607 return (NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500608 return ((png_voidp)png_ptr->mem_ptr);
609}
610#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson9c3ab682006-02-20 22:09:05 -0600611#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */