From 9436fbbf3ca0dca427c7cb8792d48dc6db34c55a Mon Sep 17 00:00:00 2001 From: "pierre.baudry" Date: Thu, 20 Oct 2016 16:30:51 +0200 Subject: [PATCH] transceiver: Fix mismatched allocations and deallocations The behaviour of a mismatched pair of allocation and deallocation is undefined Also fixes a memory leak if malloc fails (which stops the application anyway) Change-Id: I9c8bbade8531e8c9c02dcd43bac38cb954b3c89f --- Transceiver52M/ChannelizerBase.cpp | 6 ++++-- Transceiver52M/Resampler.cpp | 2 +- Transceiver52M/radioBuffer.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Transceiver52M/ChannelizerBase.cpp b/Transceiver52M/ChannelizerBase.cpp index 15768210..9989940e 100644 --- a/Transceiver52M/ChannelizerBase.cpp +++ b/Transceiver52M/ChannelizerBase.cpp @@ -80,8 +80,10 @@ bool ChannelizerBase::initFilters() return false; subFilters = (float **) malloc(sizeof(float *) * m); - if (!subFilters) + if (!subFilters) { + delete[] proto; return false; + } for (size_t i = 0; i < m; i++) { subFilters[i] = (float *) @@ -122,7 +124,7 @@ bool ChannelizerBase::initFilters() for (size_t i = 0; i < m; i++) reverse(subFilters[i], hLen); - delete proto; + delete[] proto; return true; } diff --git a/Transceiver52M/Resampler.cpp b/Transceiver52M/Resampler.cpp index 070adda3..8a73b797 100644 --- a/Transceiver52M/Resampler.cpp +++ b/Transceiver52M/Resampler.cpp @@ -61,7 +61,7 @@ bool Resampler::initFilters(float bw) partitions = (float **) malloc(sizeof(float *) * p); if (!partitions) { - free(proto); + delete[] proto; return false; } diff --git a/Transceiver52M/radioBuffer.cpp b/Transceiver52M/radioBuffer.cpp index 9e6f0799..a2b42c41 100644 --- a/Transceiver52M/radioBuffer.cpp +++ b/Transceiver52M/radioBuffer.cpp @@ -47,7 +47,7 @@ RadioBuffer::RadioBuffer(size_t numSegments, size_t segmentLen, RadioBuffer::~RadioBuffer() { - delete buffer; + delete[] buffer; } void RadioBuffer::reset()