Commit 85b55f536d68db86c1c0f316d587578c37c282c6
Merge branch '2340-prevent-unintentional-deallocation' into integration
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 | 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 | 347 | // Clone column |
| 345 | 348 | m_columns[colnum] = column.clone(); | ... | ... |