IBM Support

LI76221: ?: CAUSING DESTRUCTOR CALLED TWICE

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • An application has runtime segmentation fault.
    
    The segfault is caused by memory corruption when calling a
    destructor of the same class allocated on stack twice.
    Second (wrong) time is called when throw() is executed.
    __DoThrowV6 on stack.
    
    If changing the code from : ? to if-else, problem disappears.
    
    A reduced test case follows:
    
    
    ==========
    TEST CASE:
    ==========
    
    $cat t.C && xlC t.C && ./a.out
    extern "C" int printf(const char *, ...);
    
    struct S {
      S(int i) { printf("S::S(%d), this = 0x%lx\n", i, this); }
      ~S() { printf("S::~S(), this = 0x%lx\n", this); }
      S(const S&) { printf("S(const S&), this = 0x%lx\n", this);}
    };
    
    void bar(S s) { }
    
    void foo(bool b, S* p) {
      bar(b ? *p : S(2));
      throw 42;
    }
    
    int main() {
      try {
        S s(1);
        foo(true, &s);
      }
      catch(int i) {
        printf("caught\n");
      }
      return 0;
    }
    
    ==============
    ACTUAL OUTPUT:
    ==============
    S::S(1), this = 0x2ff229a0
    S(const S&), this = 0x2ff22908
    S::~S(), this = 0x2ff22908
    S::~S(), this = 0x2ff22908
    S::~S(), this = 0x2ff229a0
    caught
    
    ================
    EXPECTED OUTPUT:
    ================
    S::S(1), this = 0x2ff229a0
    S(const S&), this = 0x2ff22908
    S::~S(), this = 0x2ff22908
    S::~S(), this = 0x2ff229a0
    caught
    (constructor and destructor pairs should match)
    

Local fix

  • Replace conditional expressions with 'if else'.
    

Problem summary

  • PROBLEM DESCRIPTION: Double destruction of temporaries may
    occur in code using conditional expressions.
    
    USERS AFFECTED: Conditional expression used in copy-by-value
    argument.
    

Problem conclusion

  • A fix is available to ensure the exception handling state is
    corrected in the affected cases. Apply applicable service.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI76221

  • Reported component name

    XL C/C++ SLES10

  • Reported component ID

    5724U8300

  • Reported release

    A10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2011-06-10

  • Closed date

    2011-06-10

  • Last modified date

    2011-06-10

  • APAR is sysrouted FROM one or more of the following:

    IZ94726

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C/C++ SLES10

  • Fixed component ID

    5724U8300

Applicable component levels

  • RA10 PSY

       UP



Document information

More support for: XL C/C++

Software version: A.1

Reference #: LI76221

Modified date: 10 June 2011