Menu

#159 TPointer/TAPointer copy and assignment is unsafe

6.32.4
closed
5
2012-09-25
2011-06-24
No

The TPointer and TAPointer classes uses default shallow copy construction and assignment. This means that both source and destination claims ownership to the same contained pointer, which leads to double delete and crash on destruction, if not prevented manually.

Related

Wiki: Replacing_the_Borland_C++_Class_Libraries
Wiki: Upgrading_from_OWL

Discussion

  • Vidar Hasfjord

    Vidar Hasfjord - 2011-06-24

    Also: TPointer and TAPointer do not test for self-assigment, leading to an invalid pointer and double delete and crash on destruction, if not prevented manually.

     
  • Ognyan Chernokozhev

    I think that it doesn't make much sense of creating a copy of a TPointer/TAPointer object. They are simple classes with one purpose - to hold a pointer to some memory allocated in a block and release the memory when going out of scope.

    So, we can make a private copy constructor and assignment operators to prevent accidental copying and make the TPointer(T* pointer) constructor explicit to prevent casts from other TPointers

    About the TPointer<t>& operator =
    It is a good idea to check for self-assignment.</t>

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2011-11-29

    Fixed in [r1163].

     

    Related

    Commit: [r1163]


    Last edit: Vidar Hasfjord 2015-05-11
  • Vidar Hasfjord

    Vidar Hasfjord - 2012-05-20

    Regression in [r1163] fixed in [r1317].

    BUG: Syntax error in check for self-assignment in TEnvelope::operator= and TAEnvelope::operator=.

     

    Related

    Commit: [r1163]
    Commit: [r1317]


    Last edit: Vidar Hasfjord 2015-05-11

Log in to post a comment.

MongoDB Logo MongoDB