Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 2 | /* pngmem.c - stub functions for memory allocation |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | 2687fcc | 1998-01-07 20:54:20 -0600 | [diff] [blame^] | 4 | * libpng 0.97 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
| 6 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
| 7 | * Copyright (c) 1996, 1997 Andreas Dilger |
Glenn Randers-Pehrson | 2687fcc | 1998-01-07 20:54:20 -0600 | [diff] [blame^] | 8 | * Copyright (c) 1998, Glenn Randers-Pehrson |
| 9 | * January 7, 1998 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 10 | * |
| 11 | * This file provides a location for all memory allocation. Users which |
| 12 | * need special memory handling are expected to modify the code in this file |
| 13 | * to meet their needs. See the instructions at each function. |
| 14 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 15 | |
| 16 | #define PNG_INTERNAL |
| 17 | #include "png.h" |
| 18 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 19 | /* Borland DOS special memory handler */ |
| 20 | #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) |
| 21 | /* if you change this, be sure to change the one in png.h also */ |
| 22 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 23 | /* Allocate memory for a png_struct. The malloc and memset can be replaced |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 24 | by a single call to calloc() if this is thought to improve performance. */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 25 | png_voidp |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 26 | png_create_struct(int type) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 27 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 28 | png_size_t size; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 29 | png_voidp struct_ptr; |
| 30 | |
| 31 | if (type == PNG_STRUCT_INFO) |
| 32 | size = sizeof(png_info); |
| 33 | else if (type == PNG_STRUCT_PNG) |
| 34 | size = sizeof(png_struct); |
| 35 | else |
| 36 | return (png_voidp)NULL; |
| 37 | |
| 38 | if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) |
| 39 | { |
| 40 | png_memset(struct_ptr, 0, size); |
| 41 | } |
| 42 | |
| 43 | return (struct_ptr); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /* Free memory allocated by a png_create_struct() call */ |
| 48 | void |
| 49 | png_destroy_struct(png_voidp struct_ptr) |
| 50 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 51 | if (struct_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 52 | farfree (struct_ptr); |
| 53 | } |
| 54 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 55 | /* Allocate memory. For reasonable files, size should never exceed |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 56 | * 64K. However, zlib may allocate more then 64K if you don't tell |
| 57 | * it not to. See zconf.h and png.h for more information. zlib does |
| 58 | * need to allocate exactly 64K, so whatever you call here must |
| 59 | * have the ability to do that. |
| 60 | * |
| 61 | * Borland seems to have a problem in DOS mode for exactly 64K. |
| 62 | * It gives you a segment with an offset of 8 (perhaps to store it's |
| 63 | * memory stuff). zlib doesn't like this at all, so we have to |
| 64 | * detect and deal with it. This code should not be needed in |
| 65 | * Windows or OS/2 modes, and only in 16 bit mode. This code has |
| 66 | * been updated by Alexander Lehmann for version 0.89 to waste less |
| 67 | * memory. |
| 68 | * |
| 69 | * Note that we can't use png_size_t for the "size" declaration, |
| 70 | * since on some systems a png_size_t is a 16-bit quantity, and as a |
| 71 | * result, we would be truncating potentially larger memory requests |
| 72 | * (which should cause a fatal error) and introducing major problems. |
| 73 | */ |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 74 | png_voidp |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 75 | png_malloc(png_structp png_ptr, png_uint_32 size) |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 76 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 77 | png_voidp ret; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 78 | if (png_ptr == NULL || size == 0) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 79 | return ((voidp)NULL); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 80 | |
| 81 | #ifdef PNG_MAX_MALLOC_64K |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 82 | if (size > (png_uint_32)65536L) |
| 83 | png_error(png_ptr, "Cannot Allocate > 64K"); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 84 | #endif |
| 85 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 86 | if (size == (png_uint_32)65536L) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 87 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 88 | if (png_ptr->offset_table == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 89 | { |
| 90 | /* try to see if we need to do any of this fancy stuff */ |
| 91 | ret = farmalloc(size); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 92 | if (ret == NULL || ((png_size_t)ret & 0xffff)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 93 | { |
| 94 | int num_blocks; |
| 95 | png_uint_32 total_size; |
| 96 | png_bytep table; |
| 97 | int i; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 98 | png_byte huge * hptr; |
| 99 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 100 | if (ret != NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 101 | farfree(ret); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 102 | ret = NULL; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 103 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 104 | num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14)); |
| 105 | if (num_blocks < 1) |
| 106 | num_blocks = 1; |
| 107 | if (png_ptr->zlib_mem_level >= 7) |
| 108 | num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7)); |
| 109 | else |
| 110 | num_blocks++; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 111 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 112 | total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16; |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 113 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 114 | table = farmalloc(total_size); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 115 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 116 | if (table == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 117 | { |
| 118 | png_error(png_ptr, "Out of Memory"); |
| 119 | } |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 120 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 121 | if ((png_size_t)table & 0xfff0) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 122 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 123 | png_error(png_ptr, "Farmalloc didn't return normalized pointer"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 124 | } |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 125 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 126 | png_ptr->offset_table = table; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 127 | png_ptr->offset_table_ptr = farmalloc(num_blocks * |
| 128 | sizeof (png_bytep)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 129 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 130 | if (png_ptr->offset_table_ptr == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 131 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 132 | png_error(png_ptr, "Out of memory"); |
| 133 | } |
| 134 | |
| 135 | hptr = (png_byte huge *)table; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 136 | if ((png_size_t)hptr & 0xf) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 137 | { |
| 138 | hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L); |
| 139 | hptr += 16L; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 140 | } |
| 141 | for (i = 0; i < num_blocks; i++) |
| 142 | { |
| 143 | png_ptr->offset_table_ptr[i] = (png_bytep)hptr; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 144 | hptr += (png_uint_32)65536L; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 145 | } |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 146 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 147 | png_ptr->offset_table_number = num_blocks; |
| 148 | png_ptr->offset_table_count = 0; |
| 149 | png_ptr->offset_table_count_free = 0; |
| 150 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 151 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 152 | |
| 153 | if (png_ptr->offset_table_count >= png_ptr->offset_table_number) |
| 154 | png_error(png_ptr, "Out of Memory"); |
| 155 | |
| 156 | ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++]; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 157 | } |
| 158 | else |
| 159 | ret = farmalloc(size); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 160 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 161 | if (ret == NULL) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 162 | { |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 163 | png_error(png_ptr, "Out of Memory"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 166 | return ret; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 167 | } |
| 168 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 169 | /* free a pointer allocated by png_malloc(). In the default |
| 170 | configuration, png_ptr is not used, but is passed in case it |
| 171 | is needed. If ptr is NULL, return without taking any action. */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 172 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 173 | png_free(png_structp png_ptr, png_voidp ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 174 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 175 | if (png_ptr == NULL || ptr == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 176 | return; |
| 177 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 178 | if (png_ptr->offset_table != NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 179 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 180 | int i; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 181 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 182 | for (i = 0; i < png_ptr->offset_table_count; i++) |
| 183 | { |
| 184 | if (ptr == png_ptr->offset_table_ptr[i]) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 185 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 186 | ptr = NULL; |
| 187 | png_ptr->offset_table_count_free++; |
| 188 | break; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 189 | } |
| 190 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 191 | if (png_ptr->offset_table_count_free == png_ptr->offset_table_count) |
| 192 | { |
| 193 | farfree(png_ptr->offset_table); |
| 194 | farfree(png_ptr->offset_table_ptr); |
| 195 | png_ptr->offset_table = NULL; |
| 196 | png_ptr->offset_table_ptr = NULL; |
| 197 | } |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 198 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 199 | |
| 200 | if (ptr != NULL) |
| 201 | farfree(ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | #else /* Not the Borland DOS special memory handler */ |
| 205 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 206 | /* Allocate memory for a png_struct or a png_info. The malloc and |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 207 | memset can be replaced by a single call to calloc() if this is thought |
| 208 | to improve performance noticably.*/ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 209 | png_voidp |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 210 | png_create_struct(int type) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 211 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 212 | png_size_t size; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 213 | png_voidp struct_ptr; |
| 214 | |
| 215 | if (type == PNG_STRUCT_INFO) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 216 | size = sizeof(png_info); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 217 | else if (type == PNG_STRUCT_PNG) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 218 | size = sizeof(png_struct); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 219 | else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 220 | return (png_voidp)NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 221 | |
| 222 | #if defined(__TURBOC__) && !defined(__FLAT__) |
| 223 | if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) |
| 224 | #else |
| 225 | # if defined(_MSC_VER) && defined(MAXSEG_64K) |
Guy Schalnat | c21f90c | 1996-06-17 16:24:45 -0500 | [diff] [blame] | 226 | if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 227 | # else |
| 228 | if ((struct_ptr = (png_voidp)malloc(size)) != NULL) |
| 229 | # endif |
| 230 | #endif |
| 231 | { |
| 232 | png_memset(struct_ptr, 0, size); |
| 233 | } |
| 234 | |
| 235 | return (struct_ptr); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* Free memory allocated by a png_create_struct() call */ |
| 240 | void |
| 241 | png_destroy_struct(png_voidp struct_ptr) |
| 242 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 243 | if (struct_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 244 | #if defined(__TURBOC__) && !defined(__FLAT__) |
| 245 | farfree(struct_ptr); |
| 246 | #else |
| 247 | # if defined(_MSC_VER) && defined(MAXSEG_64K) |
| 248 | hfree(struct_ptr); |
| 249 | # else |
| 250 | free(struct_ptr); |
| 251 | # endif |
| 252 | #endif |
| 253 | } |
| 254 | |
| 255 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 256 | /* Allocate memory. For reasonable files, size should never exceed |
| 257 | 64K. However, zlib may allocate more then 64K if you don't tell |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 258 | it not to. See zconf.h and png.h for more information. zlib does |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 259 | need to allocate exactly 64K, so whatever you call here must |
| 260 | have the ability to do that. */ |
| 261 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 262 | png_voidp |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 263 | png_malloc(png_structp png_ptr, png_uint_32 size) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 264 | { |
| 265 | png_voidp ret; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 266 | if (png_ptr == NULL || size == 0) |
| 267 | return (NULL); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 268 | |
| 269 | #ifdef PNG_MAX_MALLOC_64K |
| 270 | if (size > (png_uint_32)65536L) |
| 271 | png_error(png_ptr, "Cannot Allocate > 64K"); |
| 272 | #endif |
| 273 | |
| 274 | #if defined(__TURBOC__) && !defined(__FLAT__) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 275 | ret = farmalloc((png_size_t)size); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 276 | #else |
| 277 | # if defined(_MSC_VER) && defined(MAXSEG_64K) |
| 278 | ret = halloc(size, 1); |
| 279 | # else |
| 280 | ret = malloc(size); |
| 281 | # endif |
| 282 | #endif |
| 283 | |
| 284 | if (ret == NULL) |
| 285 | { |
| 286 | png_error(png_ptr, "Out of Memory"); |
| 287 | } |
| 288 | |
| 289 | return ret; |
| 290 | } |
| 291 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 292 | /* Free a pointer allocated by png_malloc(). In the default |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 293 | configuration, png_ptr is not used, but is passed in case it |
| 294 | is needed. If ptr is NULL, return without taking any action. */ |
| 295 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 296 | png_free(png_structp png_ptr, png_voidp ptr) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 297 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 298 | if (png_ptr == NULL || ptr == NULL) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 299 | return; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 300 | |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 301 | #if defined(__TURBOC__) && !defined(__FLAT__) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 302 | farfree(ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 303 | #else |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 304 | # if defined(_MSC_VER) && defined(MAXSEG_64K) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 305 | hfree(ptr); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 306 | # else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 307 | free(ptr); |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 308 | # endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 309 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 312 | #endif /* Not Borland DOS special memory handler */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 313 | |