Commit 4edf58aa006816a7adcd3858fabc9893b75db49c
1 parent
089f4f79
Prevent unintentional deallocation in GFitsTable::set (#2340)
Showing
1 changed file
with
5 additions
and
2 deletions
src/fits/GFitsTable.cpp
| @@ -338,8 +338,11 @@ GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column) | @@ -338,8 +338,11 @@ GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column) | ||
| 338 | throw GException::out_of_range(G_SET1, "Column number", colnum, ncols()); | 338 | throw GException::out_of_range(G_SET1, "Column number", colnum, ncols()); |
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | - // Free existing column | ||
| 342 | - if (m_columns[colnum] != NULL) delete m_columns[colnum]; | 341 | + // Free existing column only if it differs from current column. This |
| 342 | + // prevents unintential deallocation of the argument | ||
| 343 | + if ((m_columns[colnum] != NULL) && (m_columns[colnum] != &column)) { | ||
| 344 | + delete m_columns[colnum]; | ||
| 345 | + } | ||
| 343 | 346 | ||
| 344 | // Clone column | 347 | // Clone column |
| 345 | m_columns[colnum] = column.clone(); | 348 | m_columns[colnum] = column.clone(); |