| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "Precomp.h" |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
#include "7zAlloc.h" |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifdef SZ_ALLOC_DEBUG |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
static int g_allocCount = 0; |
| 23 |
static int g_allocCountTemp = 0; |
| 24 |
|
| 25 |
static void Print_Alloc(const char *s, size_t size, int *counter) |
| 26 |
{ |
| 27 |
const unsigned size2 = (unsigned)size; |
| 28 |
fprintf(stderr, "\n%s count = %10d : %10u bytes; ", s, *counter, size2); |
| 29 |
(*counter)++; |
| 30 |
} |
| 31 |
static void Print_Free(const char *s, int *counter) |
| 32 |
{ |
| 33 |
(*counter)--; |
| 34 |
fprintf(stderr, "\n%s count = %10d", s, *counter); |
| 35 |
} |
| 36 |
#endif |
| 37 |
|
| 38 |
void *SzAlloc(ISzAllocPtr p, size_t size) |
| 39 |
{ |
| 40 |
UNUSED_VAR(p) |
| 41 |
if (size == 0) |
| 42 |
return 0; |
| 43 |
#ifdef SZ_ALLOC_DEBUG |
| 44 |
Print_Alloc("Alloc", size, &g_allocCount); |
| 45 |
#endif |
| 46 |
return malloc(size); |
| 47 |
} |
| 48 |
|
| 49 |
void SzFree(ISzAllocPtr p, void *address) |
| 50 |
{ |
| 51 |
UNUSED_VAR(p) |
| 52 |
#ifdef SZ_ALLOC_DEBUG |
| 53 |
if (address) |
| 54 |
Print_Free("Free ", &g_allocCount); |
| 55 |
#endif |
| 56 |
free(address); |
| 57 |
} |
| 58 |
|
| 59 |
void *SzAllocTemp(ISzAllocPtr p, size_t size) |
| 60 |
{ |
| 61 |
UNUSED_VAR(p) |
| 62 |
if (size == 0) |
| 63 |
return 0; |
| 64 |
#ifdef SZ_ALLOC_DEBUG |
| 65 |
Print_Alloc("Alloc_temp", size, &g_allocCountTemp); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
#endif |
| 72 |
return malloc(size); |
| 73 |
} |
| 74 |
|
| 75 |
void SzFreeTemp(ISzAllocPtr p, void *address) |
| 76 |
{ |
| 77 |
UNUSED_VAR(p) |
| 78 |
#ifdef SZ_ALLOC_DEBUG |
| 79 |
if (address) |
| 80 |
Print_Free("Free_temp ", &g_allocCountTemp); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
#endif |
| 88 |
free(address); |
| 89 |
} |