CPP 1.3 NO IDEA Avatar
  1. OMG Issue

CPP13 — _out types and nested calls

  • Key: CPP13-23
  • Legacy Issue Number: 3161
  • Status: open  
  • Source: Triodia Technologies Pty Ltd ( Michi Henning)
  • Summary:

    consider:

    // IDL

    struct VariableStruct

    { ... }

    ;

    interface I

    { void foo(out VariableStruct s); void bar(out VariableStruct s); }

    ;

    Then:

    // C++
    void
    MyImplForI::foo(VariableStruct_out s)

    { bar(s); bar(s); // Leak here }

    void
    MyImplForI::bar(VariableStruct_out s)

    { s = new VariableStruct; }

    The freeing of memory for out params relies on the default conversion
    by the _out constructor from a pointer to the _out type which, as a
    side effect, frees the memory return by the previous call. However,
    in this case, and _out param is passed to another call, so the
    assignment operator runs, not the constructor:

    T_out& operator=(T* p)

    { ptr_ = p; return *this; }

    The assignment operator doesn't free the previous memory, so we get
    the leak.

    Should the assignment operator be changed?

  • Reported: CPP 1.0 — Wed, 22 Dec 1999 05:00 GMT
  • Updated: Fri, 6 Mar 2015 20:57 GMT