Returning pointer to malloc'd area

I'm confused about the pointer to a malloc'd area. I have something similar to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char*
called_function()
{
  char *p;
  p=(char*)malloc(32);
  return p;
}

main()
{
    char *p;
    p=called_function();
    /* do some stuff */
    free(p);
}


The main code does not work unless I remove the free(). Then it works perfectly. Why is that? Or should I be handling this differently? Note: *p is not manipulated in any way inside main().
"Doesn't work" is not an error description.
The code is correct, except for line 9, which must be int main().
Your problem is somewhere else.
Topic archived. No new replies allowed.