1 //------------------------------------------------------------------------------
2 // GB_free_memory: wrapper for free
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // A wrapper for free.  If p is NULL on input, it is not freed.
11 
12 // The memory is freed using the free() function pointer passed in to GrB_init,
13 // which is typically the ANSI C free function.  The free_pool is bypassed.
14 
15 #include "GB.h"
16 
17 GB_PUBLIC   // accessed by the MATLAB tests in GraphBLAS/Test only
GB_free_memory(void ** p,size_t size_allocated)18 void GB_free_memory         // free memory, bypassing the free_pool
19 (
20     // input/output
21     void **p,               // pointer to allocated block of memory to free
22     // input
23     size_t size_allocated   // # of bytes actually allocated
24 )
25 {
26 
27     if (p != NULL && (*p) != NULL)
28     {
29         if (GB_Global_malloc_tracking_get ( ))
30         {
31             // for memory usage testing only
32             GB_Global_nmalloc_decrement ( ) ;
33         }
34         ASSERT (size_allocated == GB_Global_memtable_size (*p)) ;
35 //      printf ("\nhard free %p %ld\n", *p, size_allocated) ;
36 
37 //      if (GB_Global_I_have_RMM ( ))
38 //      {
39 //          rmmdealloc (*p, size_allocated) ;
40 //      }
41 //      else
42 
43         {
44             GB_Global_free_function (*p) ;
45         }
46 //      GB_Global_free_pool_dump (2) ; GB_Global_memtable_dump ( ) ;
47         (*p) = NULL ;
48     }
49 }
50 
51