Action #2340

Prevent de-allocation of client instances

Added by Knödlseder Jürgen almost 7 years ago. Updated almost 7 years ago.

Status:ClosedStart date:02/15/2018
Priority:NormalDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:1.5.1
Duration:

Description

If the following code is called with a reference to a column that actually exists already in the table, the column will be destroyed, leading specifically to a

libc++abi.dylib: Pure virtual function called!
exception in Python (this is specifically a Python problem which handles pointers to objects):
GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column)
{
    // Free existing column
    if (m_columns[colnum] != NULL) delete m_columns[colnum];

    // Clone column
    m_columns[colnum] = column.clone();

    // Return pointer to column
    return m_columns[colnum];
}

This can be prevented by the following code
GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column)
{
    // Free existing column only if it differs from current column. This
    // prevents deallocating the instance that is passed as argument which
    // would be
    if ((m_columns[colnum] != NULL) && (m_columns[colnum] != &column)) {
        delete m_columns[colnum];
    }

    // Clone column
    m_columns[colnum] = column.clone();

    // Return pointer to column
    return m_columns[colnum];
}

All GammaLib methods should be scanned for this potential problem and corrected.


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen almost 7 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

The GammaLib code was scanned for comparable issues and corrected similar to the GFitsTable::set method. The code was merged into devel and bugfix-1.5.1.

Also available in: Atom PDF