From 4edf58aa006816a7adcd3858fabc9893b75db49c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 15 Feb 2018 11:56:50 +0100 Subject: [PATCH] Prevent unintentional deallocation in GFitsTable::set (#2340) --- src/fits/GFitsTable.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index 7575ad6..90c9654 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -338,8 +338,11 @@ GFitsTableCol* GFitsTable::set(const int& colnum, const GFitsTableCol& column) throw GException::out_of_range(G_SET1, "Column number", colnum, ncols()); } - // Free existing column - if (m_columns[colnum] != NULL) delete m_columns[colnum]; + // Free existing column only if it differs from current column. This + // prevents unintential deallocation of the argument + if ((m_columns[colnum] != NULL) && (m_columns[colnum] != &column)) { + delete m_columns[colnum]; + } // Clone column m_columns[colnum] = column.clone(); -- libgit2 0.21.4