[Dumb question] Is this a memory leak ?

biswapesh.chattopadhyay@bt.com biswapesh.chattopadhyay@bt.com
Thu Dec 21 02:25:00 GMT 2000


Hi

Please excuse my ignorance - what happens in the following code?

char *trim(char *str)
{
  return (str + 3);
}

void f()
{
  char *str = strdup("1234567890");
  str = trim(str);
  // Do other stuff
  free(str);
  return;
}

Basically, I'm free()-ing an address which is different from the one I
malloc()-ed.

Thanks.
Biswa.


More information about the Gcc mailing list