[MERGED] osmo-trx[master]: transceiver: Fix mismatched allocations and deallocations

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Tom Tsou gerrit-no-reply at lists.osmocom.org
Mon Dec 12 21:51:09 UTC 2016


Tom Tsou has submitted this change and it was merged.

Change subject: transceiver: Fix mismatched allocations and deallocations
......................................................................


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
---
M Transceiver52M/ChannelizerBase.cpp
M Transceiver52M/Resampler.cpp
M Transceiver52M/radioBuffer.cpp
3 files changed, 6 insertions(+), 4 deletions(-)

Approvals:
  Tom Tsou: Looks good to me, approved
  Harald Welte: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/Transceiver52M/ChannelizerBase.cpp b/Transceiver52M/ChannelizerBase.cpp
index 1576821..9989940 100644
--- a/Transceiver52M/ChannelizerBase.cpp
+++ b/Transceiver52M/ChannelizerBase.cpp
@@ -80,8 +80,10 @@
 		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 @@
 	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 070adda..8a73b79 100644
--- a/Transceiver52M/Resampler.cpp
+++ b/Transceiver52M/Resampler.cpp
@@ -61,7 +61,7 @@
 
 	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 9e6f079..a2b42c4 100644
--- a/Transceiver52M/radioBuffer.cpp
+++ b/Transceiver52M/radioBuffer.cpp
@@ -47,7 +47,7 @@
 
 RadioBuffer::~RadioBuffer()
 {
-	delete buffer;
+	delete[] buffer;
 }
 
 void RadioBuffer::reset()

-- 
To view, visit https://gerrit.osmocom.org/1153
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9c8bbade8531e8c9c02dcd43bac38cb954b3c89f
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: pierre.baudry <pierre.baudry at diateam.net>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Tom Tsou <tom at tsou.cc>



More information about the gerrit-log mailing list