/src/lzma-fuzz/sdk/C/7zAlloc.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* 7zAlloc.c -- Allocation functions |
2 | | 2017-04-03 : Igor Pavlov : Public domain */ |
3 | | |
4 | | #include "Precomp.h" |
5 | | |
6 | | #include <stdlib.h> |
7 | | |
8 | | #include "7zAlloc.h" |
9 | | |
10 | | /* #define _SZ_ALLOC_DEBUG */ |
11 | | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ |
12 | | |
13 | | #ifdef _SZ_ALLOC_DEBUG |
14 | | |
15 | | #ifdef _WIN32 |
16 | | #include <windows.h> |
17 | | #endif |
18 | | |
19 | | #include <stdio.h> |
20 | | int g_allocCount = 0; |
21 | | int g_allocCountTemp = 0; |
22 | | |
23 | | #endif |
24 | | |
25 | | void *SzAlloc(ISzAllocPtr p, size_t size) |
26 | 3.24k | { |
27 | 3.24k | UNUSED_VAR(p); |
28 | 3.24k | if (size == 0) |
29 | 0 | return 0; |
30 | | #ifdef _SZ_ALLOC_DEBUG |
31 | | fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount); |
32 | | g_allocCount++; |
33 | | #endif |
34 | 3.24k | return malloc(size); |
35 | 3.24k | } |
36 | | |
37 | | void SzFree(ISzAllocPtr p, void *address) |
38 | 6.49k | { |
39 | 6.49k | UNUSED_VAR(p); |
40 | | #ifdef _SZ_ALLOC_DEBUG |
41 | | if (address != 0) |
42 | | { |
43 | | g_allocCount--; |
44 | | fprintf(stderr, "\nFree; count = %10d", g_allocCount); |
45 | | } |
46 | | #endif |
47 | 6.49k | free(address); |
48 | 6.49k | } |
49 | | |
50 | | void *SzAllocTemp(ISzAllocPtr p, size_t size) |
51 | 0 | { |
52 | 0 | UNUSED_VAR(p); |
53 | 0 | if (size == 0) |
54 | 0 | return 0; |
55 | | #ifdef _SZ_ALLOC_DEBUG |
56 | | fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp); |
57 | | g_allocCountTemp++; |
58 | | #ifdef _WIN32 |
59 | | return HeapAlloc(GetProcessHeap(), 0, size); |
60 | | #endif |
61 | | #endif |
62 | 0 | return malloc(size); |
63 | 0 | } |
64 | | |
65 | | void SzFreeTemp(ISzAllocPtr p, void *address) |
66 | 0 | { |
67 | 0 | UNUSED_VAR(p); |
68 | | #ifdef _SZ_ALLOC_DEBUG |
69 | | if (address != 0) |
70 | | { |
71 | | g_allocCountTemp--; |
72 | | fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); |
73 | | } |
74 | | #ifdef _WIN32 |
75 | | HeapFree(GetProcessHeap(), 0, address); |
76 | | return; |
77 | | #endif |
78 | | #endif |
79 | 0 | free(address); |
80 | 0 | } |