"Fossies" - the Fresh Open Source Software Archive

Member "hashcat-6.2.6/deps/LZMA-SDK/C/7zAlloc.c" (2 Sep 2022, 1595 Bytes) of package /linux/privat/hashcat-6.2.6.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.

    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 {
   27   UNUSED_VAR(p);
   28   if (size == 0)
   29     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   return malloc(size);
   35 }
   36 
   37 void SzFree(ISzAllocPtr p, void *address)
   38 {
   39   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   free(address);
   48 }
   49 
   50 void *SzAllocTemp(ISzAllocPtr p, size_t size)
   51 {
   52   UNUSED_VAR(p);
   53   if (size == 0)
   54     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   return malloc(size);
   63 }
   64 
   65 void SzFreeTemp(ISzAllocPtr p, void *address)
   66 {
   67   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   free(address);
   80 }