1 //------------------------------------------------------------------------------
2 // GrB_Monoid_free:  free a monoid
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 #include "GB.h"
11 
GrB_Monoid_free(GrB_Monoid * monoid)12 GrB_Info GrB_Monoid_free            // free a user-created monoid
13 (
14     GrB_Monoid *monoid              // handle of monoid to free
15 )
16 {
17 
18     if (monoid != NULL)
19     {
20         // only free a dynamically-allocated monoid
21         GrB_Monoid mon = *monoid ;
22         if (mon != NULL)
23         {
24             size_t header_size = mon->header_size ;
25             if (header_size > 0)
26             {
27                 mon->magic = GB_FREED ;  // to help detect dangling pointers
28                 mon->header_size = 0 ;
29                 GB_FREE (&(mon->identity), mon->identity_size) ;
30                 GB_FREE (&(mon->terminal), mon->terminal_size) ;
31                 GB_FREE (monoid, header_size) ;
32             }
33         }
34     }
35 
36     return (GrB_SUCCESS) ;
37 }
38 
39