Void and malloc( )

closed account (zb0S216C)
I have the following code segment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

void *Cell_alloc;

int Alloc_cell( void **Allocator, int Sizeof_element, int Element_count )
{
    if( ( Allocator = ( void * )calloc( Element_count, Sizeof_element ) ) == NULL )
    {
       return 0;
    }

    return 1;
}

Alloc_cell( Cell_alloc, sizeof( int ), 2 );

//...other code...

free( Cell_alloc );


Now my question. When I free Cell_alloc, will it free all the memory allocated by it with free( )? I've tried googling it but found nothing of use.
Last edited on
Where do you actually point Cell_alloc at memory that was allocated?If you take the pointer returned by calloc and have Cell_alloc point to it, then yes, it will be freed.
closed account (zb0S216C)
My mistake. This was just an example code I wrote. I've changed the code.
Topic archived. No new replies allowed.