Ensure that any deallocated pointers are set to NULL



  • virtual ~CppUnknownT()
    {
        if(_pUnk) {
            _pUnk = NULL;
            _pUnk->Release ();
    }

     

    Perhaps we should add "after your done using it". 



  • An additional closing bracket might be useful too...



  • @Viral said:

    virtual ~CppUnknownT()
    {
        if(_pUnk) {
            _pUnk = NULL;
            _pUnk->Release ();
    }

    Perhaps we should add "after your done using it". 

     

    Interesting. The version of this post I received via email had the statements in the reverse order, but still had the missing brace:

    virtual ~CppUnknownT()
    {
        if(_pUnk) {
            _pUnk->Release ();
            _pUnk = NULL;

    }

    Leading me to think WTF.... 

     



  • What missing brace! 😉

    I originally sent out the corrected code before correcting it to be incorrect. Hence the e-mail discrepancy.

    This is far to ironic for me!  



  • @Viral said:

    What missing brace! 😉

    You have two { and only one } in that code snippet.

    Not sure why that smiley's there. The brace issue isn't part of your original WTF complaint.



  • @PJH said:

    @Viral said:

    What missing brace! 😉

    You have two { and only one } in that code snippet.

    Not sure why that smiley's there. The brace issue isn't part of your original WTF complaint.

     That unexpected ) after the ; isn't going to make his code any better.



  • It's not a missing brace, it's creative indentation. There's more function, just when you weren't expecting it. To make things even more fun, the next line is the start of a nested function.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.