linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Memory Leak issue
@ 2002-11-16  6:59 Hemant Mohan
  2002-11-16 15:31 ` Jason P. Winters
  2002-11-16 23:53 ` Glynn Clements
  0 siblings, 2 replies; 5+ messages in thread
From: Hemant Mohan @ 2002-11-16  6:59 UTC (permalink / raw)
  To: linux-c-programming

Hi,
Is it possible to have a C function return a char*, and have void arguememnts 
without the caller having to free the memory??
I mean something like this:

char* foo(void)
{
   char *ret;
   .....
   .....  
  
   return(ret);
}

int main()
{
   ....
   char * temp;
   temp = foo();
   /* here I don't want to do a free(temp) */
   .....

}

To my understanding in this case the function foo will have to internally to 
do a malloc for ret before doing any processing on it. And it will not be 
able free this memory.  This implies that the calling function will have to 
free the return pointer of foo somewhere to prevent any memory leakeage.  Is 
there any alternative solution to return a char* ?

Thanks,
Hemant Mohan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-11-18  7:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-16  6:59 Memory Leak issue Hemant Mohan
2002-11-16 15:31 ` Jason P. Winters
2002-11-16 23:53 ` Glynn Clements
2002-11-18  5:57   ` Hemant Mohan
2002-11-18  7:10     ` Dimitar Peikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).