DragonFly BSD
DragonFly bugs List (threaded) for 2004-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

RE: cu coredumps

From: "Adrian Nida" <nida@xxxxxxxx>
Date: Wed, 27 Oct 2004 13:51:16 -0400

> tmp_cp = malloc(sizeof(char) * 10);
> cp = tmp_cp
> free(tmp_cp);
> tmp_cp = NULL;
> then cp would now be pointing to a block of memory that could be used by
> some other process/overwritten? Would that not make it impossible for me
> to actually free tmp_cp, as cp needs it?

This frees the memory that tmp_cp && cp both *point to*. From that point on,
if you reference cp you'll hopefully segfault because you're referencing
garbage.  Worst case, someone will put some malicious code at that memory
location and 0wn3 your box.

Also if this is a local function, pointing tmp_cp to NULL does nothing
useful except give you a clean stack.  That practice is most beneficial when
using global/member variables. 


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]