Hi I have allocated memory to a pointer to a character array using malloc
Code:
tmp_argv_pipe[index] = (char *)malloc(sizeof(char) * strlen(yytext) + 1);
Later on in this array, I put NULL values to divide and use it later.
Now I want to deallocate the memory specified to it.
For a different array pointer, I use
Code:
void free_memory(char *tmp_argv[])
{
int counter;
for(counter = 0; tmp_argv[counter] != NULL; counter++)
{
bzero(tmp_argv[counter], strlen(tmp_argv[counter])+1);
tmp_argv[counter] = NULL;
free(tmp_argv[counter]);
}
}
and it works fine.
I tried passing one more argument to the function above that gives the length of tmp_argv_pipe and then give the condition as
Code:
tmp_argv[counter] != NULL || counter <= length
It gives me segementation error when I do this.