hi;
do i need to use free with each malloc?
how could i free memory in this function:
Code:char *function(){ char * p=malloc(10*sizeof(char)); ....... .... return p; }
This is a discussion on malloc & free within the C Programming forums, part of the General Programming Boards category; hi; do i need to use free with each malloc? how could i free memory in this function: Code: char ...
hi;
do i need to use free with each malloc?
how could i free memory in this function:
Code:char *function(){ char * p=malloc(10*sizeof(char)); ....... .... return p; }
As a general rule you should.
It's also a 'guideline' to put the corresponding free() with it's malloc, but not possible in all cases, such as this.
Simply call free() on the pointer returned by 'function'.