This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Dumb question] Is this a memory leak ?


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]