On (25 Jul 97) Daniel Jones wrote to Sunir Shah...
SS> CFoo *pFoo = new CFoo;
SS> EvilFooFunc( pFoo );
SS> pFoo->member = ;
SS> void EvilFooFunc( CFoo* &pFoo )
SS> {
SS> delete pFoo;
SS> }
SS> Can you say memory leak?
DJ> Sure. Now, consider this:
DJ> int FooCopy(CFoo *, CFoo *);
DJ> void EvilCFooFunc(CFoo *);
DJ> CFoo *pFoo = malloc(sizeof(CFoo));
DJ> EvilCFooFunc(pFoo);
DJ> FooCopy(pFoo, pAnotherFoo);
DJ> void EvilCFooFunc(CFoo *p)
DJ> {
DJ> free p;
DJ> }
or even something as simple as:
#define evilfunc(arg) func(&arg)
This allows C code to cause problems just like C++ code can - in the
client code, it doesn't look like any pointers are involved at all, so
it appears that whatever is passed as an argument can't possibly be
affected by the function.
Of course in either case, a little examination of the header reveals
exactly what's going on.
I think there are two basic lessons here: 1) you can write as bad of
code as you want to, almost regardless of language, and 2) if you use
code without knowing at least a little about what it does, you get
exactly what you deserve.
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|