From 7afe4cf0bf6f2dfa0434ee48610e19fef5071f9c Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 4 Oct 2015 14:28:55 +0100 Subject: [PATCH] Fix spect_data memory leak in SpectFrame::ImportSPC2 when nx is 0. --- src/spect.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/spect.cpp b/src/spect.cpp index 2181e83d..493cb8d9 100644 --- a/src/spect.cpp +++ b/src/spect.cpp @@ -256,25 +256,33 @@ int SpectFrame::ImportSPC2(wxInputStream& stream, float &time_acc) if(cy.flags & 0x04) markers |= 8; - spect_data = new USHORT[nx]; - - if(spect_data == NULL) + if(nx>0) { - wxLogError(_T("Failed to allocate memory")); - return(1); - } + spect_data = new USHORT[nx]; - max_y = 0; - for(ix=0; ixdata[ix]; - if(spect_data[ix] > max_y) - max_y = spect_data[ix]; + if(spect_data == NULL) + { + wxLogError(_T("Failed to allocate memory")); + return(1); + } + + max_y = 0; + for(ix=0; ixdata[ix]; + if(spect_data[ix] > max_y) + max_y = spect_data[ix]; + } } - if(nx==0) + else { nx = int(8000/dx); spect_data = new USHORT[nx]; + if(spect_data == NULL) + { + wxLogError(_T("Failed to allocate memory")); + return(1); + } for(ix=0; ix