"Fossies" - the Fresh Open Source Software Archive

Member "clamav-0.102.3/libclamav/7z/7zAlloc.c" (12 May 2020, 1531 Bytes) of package /linux/misc/clamav-0.102.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "7zAlloc.c" see the Fossies "Dox" file reference documentation.

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