summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/mem.c
diff options
context:
space:
mode:
authorjsing <>2014-04-15 13:42:55 +0000
committerjsing <>2014-04-15 13:42:55 +0000
commit69a8d2dcc19aed0d1116ba2ecd81cce5ae736c94 (patch)
treef085d85cb06e6b6e1a1b1d52cced54d9f7d7e5f2 /src/lib/libcrypto/mem.c
parentc7fdfc89ee30180bf262c4b146c1b6e1030083d6 (diff)
downloadopenbsd-69a8d2dcc19aed0d1116ba2ecd81cce5ae736c94.tar.gz
openbsd-69a8d2dcc19aed0d1116ba2ecd81cce5ae736c94.tar.bz2
openbsd-69a8d2dcc19aed0d1116ba2ecd81cce5ae736c94.zip
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using tr and md5.
Diffstat (limited to 'src/lib/libcrypto/mem.c')
-rw-r--r--src/lib/libcrypto/mem.c443
1 files changed, 240 insertions, 203 deletions
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
index 55e829dc92..86e5ff1c8e 100644
--- a/src/lib/libcrypto/mem.c
+++ b/src/lib/libcrypto/mem.c
@@ -62,206 +62,230 @@
62#include "cryptlib.h" 62#include "cryptlib.h"
63 63
64 64
65static int allow_customize = 1; /* we provide flexible functions for */ 65static int allow_customize = 1;
66static int allow_customize_debug = 1;/* exchanging memory-related functions at 66/* we provide flexible functions for */
67 * run-time, but this must be done 67static int allow_customize_debug = 1;/* exchanging memory - related functions at
68 * before any blocks are actually 68 * run - time, but this must be done
69 * allocated; or we'll run into huge 69 * before any blocks are actually
70 * problems when malloc/free pairs 70 * allocated; or we'll run into huge
71 * don't match etc. */ 71 * problems when malloc/free pairs
72 72 * don't match etc. */
73
74 73
75/* the following pointers may be changed as long as 'allow_customize' is set */ 74/* the following pointers may be changed as long as 'allow_customize' is set */
76 75
77static void *(*malloc_func)(size_t) = malloc; 76static void *(*malloc_func)(size_t) = malloc;
78static void *default_malloc_ex(size_t num, const char *file, int line) 77static void
79 { return malloc_func(num); } 78*default_malloc_ex(size_t num, const char *file, int line)
80static void *(*malloc_ex_func)(size_t, const char *file, int line) 79{
81 = default_malloc_ex; 80 return malloc_func(num);
82 81}
83static void *(*realloc_func)(void *, size_t)= realloc; 82static void *(*malloc_ex_func)(size_t, const char *file, int line) =
84static void *default_realloc_ex(void *str, size_t num, 83 default_malloc_ex;
85 const char *file, int line) 84
86 { return realloc_func(str,num); } 85static void *(*realloc_func)(void *, size_t) = realloc;
87static void *(*realloc_ex_func)(void *, size_t, const char *file, int line) 86static void
88 = default_realloc_ex; 87*default_realloc_ex(void *str, size_t num, const char *file, int line)
89 88{
90static void (*free_func)(void *) = free; 89 return realloc_func(str, num);
91 90}
92static void *(*malloc_locked_func)(size_t) = malloc; 91static void *(*realloc_ex_func)(void *, size_t, const char *file, int line) =
93static void *default_malloc_locked_ex(size_t num, const char *file, int line) 92 default_realloc_ex;
94 { return malloc_locked_func(num); } 93
95static void *(*malloc_locked_ex_func)(size_t, const char *file, int line) 94static void (*free_func)(void *) = free;
96 = default_malloc_locked_ex; 95
97 96static void *(*malloc_locked_func)(size_t) = malloc;
98static void (*free_locked_func)(void *) = free; 97static void
99 98*default_malloc_locked_ex(size_t num, const char *file, int line)
99{
100 return malloc_locked_func(num);
101}
102static void *(*malloc_locked_ex_func)(size_t, const char *file, int line) =
103 default_malloc_locked_ex;
104
105static void (*free_locked_func)(void *) = free;
100 106
101 107
102/* may be changed as long as 'allow_customize_debug' is set */ 108/* may be changed as long as 'allow_customize_debug' is set */
103/* XXX use correct function pointer types */ 109/* XXX use correct function pointer types */
104#ifdef CRYPTO_MDEBUG 110#ifdef CRYPTO_MDEBUG
105/* use default functions from mem_dbg.c */ 111/* use default functions from mem_dbg.c */
106static void (*malloc_debug_func)(void *,int,const char *,int,int) 112static void (*malloc_debug_func)(void *, int, const char *, int, int) =
107 = CRYPTO_dbg_malloc; 113 CRYPTO_dbg_malloc;
108static void (*realloc_debug_func)(void *,void *,int,const char *,int,int) 114static void (*realloc_debug_func)(void *, void *, int, const char *, int, int) =
109 = CRYPTO_dbg_realloc; 115 CRYPTO_dbg_realloc;
110static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free; 116static void (*free_debug_func)(void *, int) = CRYPTO_dbg_free;
111static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options; 117static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options;
112static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options; 118static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options;
113#else 119#else
114/* applications can use CRYPTO_malloc_debug_init() to select above case 120/* applications can use CRYPTO_malloc_debug_init() to select above case
115 * at run-time */ 121 * at run-time */
116static void (*malloc_debug_func)(void *,int,const char *,int,int) = NULL; 122static void (*malloc_debug_func)(void *, int, const char *, int, int) = NULL;
117static void (*realloc_debug_func)(void *,void *,int,const char *,int,int) 123static void (*realloc_debug_func)(void *, void *, int, const char *, int, int) =
118 = NULL; 124 NULL;
119static void (*free_debug_func)(void *,int) = NULL; 125static void (*free_debug_func)(void *, int) = NULL;
120static void (*set_debug_options_func)(long) = NULL; 126static void (*set_debug_options_func)(long) = NULL;
121static long (*get_debug_options_func)(void) = NULL; 127static long (*get_debug_options_func)(void) = NULL;
122#endif 128#endif
123 129
124int CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t), 130int
125 void (*f)(void *)) 131CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
126 { 132 void (*f)(void *))
133{
127 /* Dummy call just to ensure OPENSSL_init() gets linked in */ 134 /* Dummy call just to ensure OPENSSL_init() gets linked in */
128 OPENSSL_init(); 135 OPENSSL_init();
129 if (!allow_customize) 136 if (!allow_customize)
130 return 0; 137 return 0;
131 if ((m == 0) || (r == 0) || (f == 0)) 138 if ((m == 0) || (r == 0) || (f == 0))
132 return 0; 139 return 0;
133 malloc_func=m; malloc_ex_func=default_malloc_ex; 140 malloc_func = m;
134 realloc_func=r; realloc_ex_func=default_realloc_ex; 141 malloc_ex_func = default_malloc_ex;
135 free_func=f; 142 realloc_func = r;
136 malloc_locked_func=m; malloc_locked_ex_func=default_malloc_locked_ex; 143 realloc_ex_func = default_realloc_ex;
137 free_locked_func=f; 144 free_func = f;
145 malloc_locked_func = m;
146 malloc_locked_ex_func = default_malloc_locked_ex;
147 free_locked_func = f;
138 return 1; 148 return 1;
139 } 149}
140 150
141int CRYPTO_set_mem_ex_functions( 151int
142 void *(*m)(size_t,const char *,int), 152CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int),
143 void *(*r)(void *, size_t,const char *,int), 153 void *(*r)(void *, size_t, const char *, int), void (*f)(void *))
144 void (*f)(void *)) 154{
145 {
146 if (!allow_customize) 155 if (!allow_customize)
147 return 0; 156 return 0;
148 if ((m == 0) || (r == 0) || (f == 0)) 157 if ((m == 0) || (r == 0) || (f == 0))
149 return 0; 158 return 0;
150 malloc_func=0; malloc_ex_func=m; 159 malloc_func = 0;
151 realloc_func=0; realloc_ex_func=r; 160 malloc_ex_func = m;
152 free_func=f; 161 realloc_func = 0;
153 malloc_locked_func=0; malloc_locked_ex_func=m; 162 realloc_ex_func = r;
154 free_locked_func=f; 163 free_func = f;
164 malloc_locked_func = 0;
165 malloc_locked_ex_func = m;
166 free_locked_func = f;
155 return 1; 167 return 1;
156 } 168}
157 169
158int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *)) 170int
159 { 171CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
172{
160 if (!allow_customize) 173 if (!allow_customize)
161 return 0; 174 return 0;
162 if ((m == NULL) || (f == NULL)) 175 if ((m == NULL) || (f == NULL))
163 return 0; 176 return 0;
164 malloc_locked_func=m; malloc_locked_ex_func=default_malloc_locked_ex; 177 malloc_locked_func = m;
165 free_locked_func=f; 178 malloc_locked_ex_func = default_malloc_locked_ex;
179 free_locked_func = f;
166 return 1; 180 return 1;
167 } 181}
168 182
169int CRYPTO_set_locked_mem_ex_functions( 183int CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int),
170 void *(*m)(size_t,const char *,int), 184 void (*f)(void *))
171 void (*f)(void *)) 185{
172 {
173 if (!allow_customize) 186 if (!allow_customize)
174 return 0; 187 return 0;
175 if ((m == NULL) || (f == NULL)) 188 if ((m == NULL) || (f == NULL))
176 return 0; 189 return 0;
177 malloc_locked_func=0; malloc_locked_ex_func=m; 190 malloc_locked_func = 0;
178 free_func=f; 191 malloc_locked_ex_func = m;
192 free_func = f;
179 return 1; 193 return 1;
180 } 194}
181 195
182int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int), 196int
183 void (*r)(void *,void *,int,const char *,int,int), 197CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int),
184 void (*f)(void *,int), 198 void (*r)(void *, void *, int, const char *, int, int),
185 void (*so)(long), 199 void (*f)(void *, int), void (*so)(long), long (*go)(void))
186 long (*go)(void)) 200{
187 {
188 if (!allow_customize_debug) 201 if (!allow_customize_debug)
189 return 0; 202 return 0;
190 OPENSSL_init(); 203 OPENSSL_init();
191 malloc_debug_func=m; 204 malloc_debug_func = m;
192 realloc_debug_func=r; 205 realloc_debug_func = r;
193 free_debug_func=f; 206 free_debug_func = f;
194 set_debug_options_func=so; 207 set_debug_options_func = so;
195 get_debug_options_func=go; 208 get_debug_options_func = go;
196 return 1; 209 return 1;
197 } 210}
198 211
199 212
200void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t), 213void
201 void (**f)(void *)) 214CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
202 { 215 void (**f)(void *))
203 if (m != NULL) *m = (malloc_ex_func == default_malloc_ex) ? 216{
204 malloc_func : 0; 217 if (m != NULL)
205 if (r != NULL) *r = (realloc_ex_func == default_realloc_ex) ? 218 *m = (malloc_ex_func == default_malloc_ex) ? malloc_func : 0;
206 realloc_func : 0; 219 if (r != NULL)
207 if (f != NULL) *f=free_func; 220 *r = (realloc_ex_func == default_realloc_ex) ? realloc_func : 0;
208 } 221 if (f != NULL)
209 222 *f = free_func;
210void CRYPTO_get_mem_ex_functions( 223}
211 void *(**m)(size_t,const char *,int), 224
212 void *(**r)(void *, size_t,const char *,int), 225void CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int),
213 void (**f)(void *)) 226 void *(**r)(void *, size_t, const char *, int), void (**f)(void *))
214 { 227{
215 if (m != NULL) *m = (malloc_ex_func != default_malloc_ex) ? 228 if (m != NULL)
216 malloc_ex_func : 0; 229 *m = (malloc_ex_func != default_malloc_ex) ? malloc_ex_func : 0;
217 if (r != NULL) *r = (realloc_ex_func != default_realloc_ex) ? 230 if (r != NULL)
218 realloc_ex_func : 0; 231 *r = (realloc_ex_func != default_realloc_ex) ?
219 if (f != NULL) *f=free_func; 232 realloc_ex_func : 0;
220 } 233 if (f != NULL)
221 234 *f = free_func;
222void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *)) 235}
223 { 236
224 if (m != NULL) *m = (malloc_locked_ex_func == default_malloc_locked_ex) ? 237void
225 malloc_locked_func : 0; 238CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
226 if (f != NULL) *f=free_locked_func; 239{
227 } 240 if (m != NULL)
228 241 *m = (malloc_locked_ex_func == default_malloc_locked_ex) ?
229void CRYPTO_get_locked_mem_ex_functions( 242 malloc_locked_func : 0;
230 void *(**m)(size_t,const char *,int), 243 if (f != NULL)
231 void (**f)(void *)) 244 *f = free_locked_func;
232 { 245}
233 if (m != NULL) *m = (malloc_locked_ex_func != default_malloc_locked_ex) ? 246
234 malloc_locked_ex_func : 0; 247void CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int),
235 if (f != NULL) *f=free_locked_func; 248 void (**f)(void *))
236 } 249{
237 250 if (m != NULL)
238void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int), 251 *m = (malloc_locked_ex_func != default_malloc_locked_ex) ?
239 void (**r)(void *,void *,int,const char *,int,int), 252 malloc_locked_ex_func : 0;
240 void (**f)(void *,int), 253 if (f != NULL)
241 void (**so)(long), 254 *f = free_locked_func;
242 long (**go)(void)) 255}
243 { 256
244 if (m != NULL) *m=malloc_debug_func; 257void
245 if (r != NULL) *r=realloc_debug_func; 258CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int),
246 if (f != NULL) *f=free_debug_func; 259 void (**r)(void *, void *, int, const char *, int, int),
247 if (so != NULL) *so=set_debug_options_func; 260 void (**f)(void *, int), void (**so)(long), long (**go)(void))
248 if (go != NULL) *go=get_debug_options_func; 261{
249 } 262 if (m != NULL)
250 263 *m = malloc_debug_func;
251 264 if (r != NULL)
252void *CRYPTO_malloc_locked(int num, const char *file, int line) 265 *r = realloc_debug_func;
253 { 266 if (f != NULL)
267 *f = free_debug_func;
268 if (so != NULL)
269 *so = set_debug_options_func;
270 if (go != NULL)
271 *go = get_debug_options_func;
272}
273
274
275void
276*CRYPTO_malloc_locked(int num, const char *file, int line)
277{
254 void *ret = NULL; 278 void *ret = NULL;
255 279
256 if (num <= 0) return NULL; 280 if (num <= 0)
281 return NULL;
257 282
258 allow_customize = 0; 283 allow_customize = 0;
259 if (malloc_debug_func != NULL) 284 if (malloc_debug_func != NULL) {
260 {
261 allow_customize_debug = 0; 285 allow_customize_debug = 0;
262 malloc_debug_func(NULL, num, file, line, 0); 286 malloc_debug_func(NULL, num, file, line, 0);
263 } 287 }
264 ret = malloc_locked_ex_func(num,file,line); 288 ret = malloc_locked_ex_func(num, file, line);
265#ifdef LEVITTE_DEBUG_MEM 289#ifdef LEVITTE_DEBUG_MEM
266 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num); 290 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
267#endif 291#endif
@@ -272,17 +296,18 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
272 /* Create a dependency on the value of 'cleanse_ctr' so our memory 296 /* Create a dependency on the value of 'cleanse_ctr' so our memory
273 * sanitisation function can't be optimised out. NB: We only do 297 * sanitisation function can't be optimised out. NB: We only do
274 * this for >2Kb so the overhead doesn't bother us. */ 298 * this for >2Kb so the overhead doesn't bother us. */
275 if(ret && (num > 2048)) 299 if (ret && (num > 2048)) {
276 { extern unsigned char cleanse_ctr; 300 extern unsigned char cleanse_ctr;
277 ((unsigned char *)ret)[0] = cleanse_ctr; 301 ((unsigned char *)ret)[0] = cleanse_ctr;
278 } 302 }
279#endif 303#endif
280 304
281 return ret; 305 return ret;
282 } 306}
283 307
284void CRYPTO_free_locked(void *str) 308void
285 { 309CRYPTO_free_locked(void *str)
310{
286 if (free_debug_func != NULL) 311 if (free_debug_func != NULL)
287 free_debug_func(str, 0); 312 free_debug_func(str, 0);
288#ifdef LEVITTE_DEBUG_MEM 313#ifdef LEVITTE_DEBUG_MEM
@@ -291,21 +316,22 @@ void CRYPTO_free_locked(void *str)
291 free_locked_func(str); 316 free_locked_func(str);
292 if (free_debug_func != NULL) 317 if (free_debug_func != NULL)
293 free_debug_func(NULL, 1); 318 free_debug_func(NULL, 1);
294 } 319}
295 320
296void *CRYPTO_malloc(int num, const char *file, int line) 321void
297 { 322*CRYPTO_malloc(int num, const char *file, int line)
323{
298 void *ret = NULL; 324 void *ret = NULL;
299 325
300 if (num <= 0) return NULL; 326 if (num <= 0)
327 return NULL;
301 328
302 allow_customize = 0; 329 allow_customize = 0;
303 if (malloc_debug_func != NULL) 330 if (malloc_debug_func != NULL) {
304 {
305 allow_customize_debug = 0; 331 allow_customize_debug = 0;
306 malloc_debug_func(NULL, num, file, line, 0); 332 malloc_debug_func(NULL, num, file, line, 0);
307 } 333 }
308 ret = malloc_ex_func(num,file,line); 334 ret = malloc_ex_func(num, file, line);
309#ifdef LEVITTE_DEBUG_MEM 335#ifdef LEVITTE_DEBUG_MEM
310 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num); 336 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
311#endif 337#endif
@@ -316,35 +342,39 @@ void *CRYPTO_malloc(int num, const char *file, int line)
316 /* Create a dependency on the value of 'cleanse_ctr' so our memory 342 /* Create a dependency on the value of 'cleanse_ctr' so our memory
317 * sanitisation function can't be optimised out. NB: We only do 343 * sanitisation function can't be optimised out. NB: We only do
318 * this for >2Kb so the overhead doesn't bother us. */ 344 * this for >2Kb so the overhead doesn't bother us. */
319 if(ret && (num > 2048)) 345 if (ret && (num > 2048)) {
320 { extern unsigned char cleanse_ctr; 346 extern unsigned char cleanse_ctr;
321 ((unsigned char *)ret)[0] = cleanse_ctr; 347 ((unsigned char *)ret)[0] = cleanse_ctr;
322 } 348 }
323#endif 349#endif
324 350
325 return ret; 351 return ret;
326 } 352}
327char *CRYPTO_strdup(const char *str, const char *file, int line) 353
328 { 354char
329 size_t len = strlen(str)+1; 355*CRYPTO_strdup(const char *str, const char *file, int line)
356{
357 size_t len = strlen(str) + 1;
330 char *ret = CRYPTO_malloc(len, file, line); 358 char *ret = CRYPTO_malloc(len, file, line);
331 359
332 memcpy(ret, str, len); 360 memcpy(ret, str, len);
333 return ret; 361 return ret;
334 } 362}
335 363
336void *CRYPTO_realloc(void *str, int num, const char *file, int line) 364void
337 { 365*CRYPTO_realloc(void *str, int num, const char *file, int line)
366{
338 void *ret = NULL; 367 void *ret = NULL;
339 368
340 if (str == NULL) 369 if (str == NULL)
341 return CRYPTO_malloc(num, file, line); 370 return CRYPTO_malloc(num, file, line);
342 371
343 if (num <= 0) return NULL; 372 if (num <= 0)
373 return NULL;
344 374
345 if (realloc_debug_func != NULL) 375 if (realloc_debug_func != NULL)
346 realloc_debug_func(str, NULL, num, file, line, 0); 376 realloc_debug_func(str, NULL, num, file, line, 0);
347 ret = realloc_ex_func(str,num,file,line); 377 ret = realloc_ex_func(str, num, file, line);
348#ifdef LEVITTE_DEBUG_MEM 378#ifdef LEVITTE_DEBUG_MEM
349 fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num); 379 fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num);
350#endif 380#endif
@@ -352,44 +382,47 @@ void *CRYPTO_realloc(void *str, int num, const char *file, int line)
352 realloc_debug_func(str, ret, num, file, line, 1); 382 realloc_debug_func(str, ret, num, file, line, 1);
353 383
354 return ret; 384 return ret;
355 } 385}
356 386
357void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file, 387void
358 int line) 388*CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file,
359 { 389int line)
390{
360 void *ret = NULL; 391 void *ret = NULL;
361 392
362 if (str == NULL) 393 if (str == NULL)
363 return CRYPTO_malloc(num, file, line); 394 return CRYPTO_malloc(num, file, line);
364 395
365 if (num <= 0) return NULL; 396 if (num <= 0)
397 return NULL;
366 398
367 /* We don't support shrinking the buffer. Note the memcpy that copies 399 /* We don't support shrinking the buffer. Note the memcpy that copies
368 * |old_len| bytes to the new buffer, below. */ 400 * |old_len| bytes to the new buffer, below. */
369 if (num < old_len) return NULL; 401 if (num < old_len)
402 return NULL;
370 403
371 if (realloc_debug_func != NULL) 404 if (realloc_debug_func != NULL)
372 realloc_debug_func(str, NULL, num, file, line, 0); 405 realloc_debug_func(str, NULL, num, file, line, 0);
373 ret=malloc_ex_func(num,file,line); 406 ret = malloc_ex_func(num, file, line);
374 if(ret) 407 if (ret) {
375 { 408 memcpy(ret, str, old_len);
376 memcpy(ret,str,old_len); 409 OPENSSL_cleanse(str, old_len);
377 OPENSSL_cleanse(str,old_len);
378 free_func(str); 410 free_func(str);
379 } 411 }
380#ifdef LEVITTE_DEBUG_MEM 412#ifdef LEVITTE_DEBUG_MEM
381 fprintf(stderr, 413 fprintf(stderr,
382 "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", 414 "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n",
383 str, ret, num); 415 str, ret, num);
384#endif 416#endif
385 if (realloc_debug_func != NULL) 417 if (realloc_debug_func != NULL)
386 realloc_debug_func(str, ret, num, file, line, 1); 418 realloc_debug_func(str, ret, num, file, line, 1);
387 419
388 return ret; 420 return ret;
389 } 421}
390 422
391void CRYPTO_free(void *str) 423void
392 { 424CRYPTO_free(void *str)
425{
393 if (free_debug_func != NULL) 426 if (free_debug_func != NULL)
394 free_debug_func(str, 0); 427 free_debug_func(str, 0);
395#ifdef LEVITTE_DEBUG_MEM 428#ifdef LEVITTE_DEBUG_MEM
@@ -398,24 +431,28 @@ void CRYPTO_free(void *str)
398 free_func(str); 431 free_func(str);
399 if (free_debug_func != NULL) 432 if (free_debug_func != NULL)
400 free_debug_func(NULL, 1); 433 free_debug_func(NULL, 1);
401 } 434}
402 435
403void *CRYPTO_remalloc(void *a, int num, const char *file, int line) 436void
404 { 437*CRYPTO_remalloc(void *a, int num, const char *file, int line)
405 if (a != NULL) OPENSSL_free(a); 438{
406 a=(char *)OPENSSL_malloc(num); 439 if (a != NULL)
407 return(a); 440 OPENSSL_free(a);
408 } 441 a = (char *)OPENSSL_malloc(num);
409 442 return (a);
410void CRYPTO_set_mem_debug_options(long bits) 443}
411 { 444
445void
446CRYPTO_set_mem_debug_options(long bits)
447{
412 if (set_debug_options_func != NULL) 448 if (set_debug_options_func != NULL)
413 set_debug_options_func(bits); 449 set_debug_options_func(bits);
414 } 450}
415 451
416long CRYPTO_get_mem_debug_options(void) 452long
417 { 453CRYPTO_get_mem_debug_options(void)
454{
418 if (get_debug_options_func != NULL) 455 if (get_debug_options_func != NULL)
419 return get_debug_options_func(); 456 return get_debug_options_func();
420 return 0; 457 return 0;
421 } 458}