All of lore.kernel.org
 help / color / mirror / Atom feed
* Any problem ?
@ 2011-01-28 11:53 ratheesh k
  2011-01-28 12:02 ` Santosh Sivaraj
       [not found] ` <AANLkTimg=+0jUVjyG2Zq7ZqC=A5XbjWfkjoJADmPsULK@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: ratheesh k @ 2011-01-28 11:53 UTC (permalink / raw)
  To: linux-c-programming

Is there any problem with this below code ? I just want to free memory.


void free_it(char *ptr)
{
 free(ptr);
}


int main()
{
char *str = (char *)malloc(100);
strcpy(str, "Ratheesh");
free_it(str);
str=NULL;
return 0;
}

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

* Re: Any problem ?
  2011-01-28 11:53 Any problem ? ratheesh k
@ 2011-01-28 12:02 ` Santosh Sivaraj
       [not found] ` <AANLkTimg=+0jUVjyG2Zq7ZqC=A5XbjWfkjoJADmPsULK@mail.gmail.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Santosh Sivaraj @ 2011-01-28 12:02 UTC (permalink / raw)
  To: ratheesh k; +Cc: linux-c-programming

On 01/28/2011 05:23 PM, ratheesh k wrote:
> void free_it(char *ptr)
> {
>   free(ptr);
> }
>
>
> int main()
> {
> char *str = (char *)malloc(100);
> strcpy(str, "Ratheesh");
> free_it(str);
> str=NULL;
> return 0;
> }
Nothing is wrong.. should work fine.

Santosh
--
http://fossix.org

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

* Re: Any problem ?
       [not found] ` <AANLkTimg=+0jUVjyG2Zq7ZqC=A5XbjWfkjoJADmPsULK@mail.gmail.com>
@ 2011-01-28 20:46   ` Leon Romanovsky
  2011-01-28 21:01     ` David Astua
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2011-01-28 20:46 UTC (permalink / raw)
  To: ratheesh k; +Cc: linux-c-programming

> str=NULL;
In general, you don't need this line.

--
"Change is inevitable; progress is optional".

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

* Re: Any problem ?
  2011-01-28 20:46   ` Leon Romanovsky
@ 2011-01-28 21:01     ` David Astua
  0 siblings, 0 replies; 4+ messages in thread
From: David Astua @ 2011-01-28 21:01 UTC (permalink / raw)
  To: Leon Romanovsky; +Cc: ratheesh k, linux-c-programming

On Fri, Jan 28, 2011 at 2:46 PM, Leon Romanovsky <leon@leon.nu> wrote:
>> str=NULL;
> In general, you don't need this line.
>
> --
> "Change is inevitable; progress is optional".
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

Anyway is a good practice i think, to avoid double-free problems on
more complex code.
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2011-01-28 21:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 11:53 Any problem ? ratheesh k
2011-01-28 12:02 ` Santosh Sivaraj
     [not found] ` <AANLkTimg=+0jUVjyG2Zq7ZqC=A5XbjWfkjoJADmPsULK@mail.gmail.com>
2011-01-28 20:46   ` Leon Romanovsky
2011-01-28 21:01     ` David Astua

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.