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
This commit is contained in:
pierre.baudry 2016-10-20 16:30:51 +02:00
parent 93ca09ea61
commit 9436fbbf3c
3 changed files with 6 additions and 4 deletions

View File

@ -80,8 +80,10 @@ bool ChannelizerBase::initFilters()
return false; return false;
subFilters = (float **) malloc(sizeof(float *) * m); subFilters = (float **) malloc(sizeof(float *) * m);
if (!subFilters) if (!subFilters) {
delete[] proto;
return false; return false;
}
for (size_t i = 0; i < m; i++) { for (size_t i = 0; i < m; i++) {
subFilters[i] = (float *) subFilters[i] = (float *)
@ -122,7 +124,7 @@ bool ChannelizerBase::initFilters()
for (size_t i = 0; i < m; i++) for (size_t i = 0; i < m; i++)
reverse(subFilters[i], hLen); reverse(subFilters[i], hLen);
delete proto; delete[] proto;
return true; return true;
} }

View File

@ -61,7 +61,7 @@ bool Resampler::initFilters(float bw)
partitions = (float **) malloc(sizeof(float *) * p); partitions = (float **) malloc(sizeof(float *) * p);
if (!partitions) { if (!partitions) {
free(proto); delete[] proto;
return false; return false;
} }

View File

@ -47,7 +47,7 @@ RadioBuffer::RadioBuffer(size_t numSegments, size_t segmentLen,
RadioBuffer::~RadioBuffer() RadioBuffer::~RadioBuffer()
{ {
delete buffer; delete[] buffer;
} }
void RadioBuffer::reset() void RadioBuffer::reset()