Debian Codegraph @

utils/lzma/SRC/7zip/Archive/7z_C/7zAlloc.c

raw
1 /* 7zAlloc.c */
2
3 #include <stdlib.h>
4 #include "7zAlloc.h"
5
6 /* #define _SZ_ALLOC_DEBUG */
7 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
8
9 #ifdef _SZ_ALLOC_DEBUG
10 #include <stdio.h>
11 int g_allocCount = 0;
12 int g_allocCountTemp = 0;
13 #endif
14
15 void *SzAlloc(size_t size)
16 {
17 if (size == 0)
18 return 0;
19 #ifdef _SZ_ALLOC_DEBUG
20 fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount);
21 g_allocCount++;
22 #endif
23 return malloc(size);
24 }
25
26 void SzFree(void *address)
27 {
28 #ifdef _SZ_ALLOC_DEBUG
29 if (address != 0)
30 {
31 g_allocCount--;
32 fprintf(stderr, "\nFree; count = %10d", g_allocCount);
33 }
34 #endif
35 free(address);
36 }
37
38 void *SzAllocTemp(size_t size)
39 {
40 if (size == 0)
41 return 0;
42 #ifdef _SZ_ALLOC_DEBUG
43 fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp);
44 g_allocCountTemp++;
45 #endif
46 return malloc(size);
47 }
48
49 void SzFreeTemp(void *address)
50 {
51 #ifdef _SZ_ALLOC_DEBUG
52 if (address != 0)
53 {
54 g_allocCountTemp--;
55 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
56 }
57 #endif
58 free(address);
59 }