aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMoritz Fischer <moritz.fischer@ettus.com>2019-01-27 13:33:25 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-02-15 11:37:03 -0800
commit5f10611c16b4c5b7e68cba7d8f0252ebcdf2c750 (patch)
treef8ccf58a3bb3e56b5ecf9eedac7888caf2b729e7 /host
parent0f6ef4bf6ed476fa7d10aef9b0af1337d1bbdf80 (diff)
downloaduhd-5f10611c16b4c5b7e68cba7d8f0252ebcdf2c750.tar.gz
uhd-5f10611c16b4c5b7e68cba7d8f0252ebcdf2c750.tar.bz2
uhd-5f10611c16b4c5b7e68cba7d8f0252ebcdf2c750.zip
examples: tx_samples_c: Fix memory leak
Fix memory leak: 'buff' was never freed. While we're at it replace the kludgy malloc(n*y*sizeof(float)) by calloc(sizeof(float), n*y). Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
Diffstat (limited to 'host')
-rw-r--r--host/examples/tx_samples_c.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/host/examples/tx_samples_c.c b/host/examples/tx_samples_c.c
index eab061edb..f9001f2f1 100644
--- a/host/examples/tx_samples_c.c
+++ b/host/examples/tx_samples_c.c
@@ -185,7 +185,7 @@ int main(int argc, char* argv[]){
uhd_tx_streamer_max_num_samps(tx_streamer, &samps_per_buff)
)
fprintf(stderr, "Buffer size in samples: %zu\n", samps_per_buff);
- buff = malloc(samps_per_buff * 2 * sizeof(float));
+ buff = calloc(sizeof(float), samps_per_buff * 2);
buffs_ptr = (const void**)&buff;
size_t i = 0;
for(i = 0; i < (samps_per_buff*2); i+=2){
@@ -205,7 +205,7 @@ int main(int argc, char* argv[]){
if (stop_signal_called) break;
if (total_num_samps > 0 && num_acc_samps >= total_num_samps) break;
- EXECUTE_OR_GOTO(free_tx_streamer,
+ EXECUTE_OR_GOTO(free_buff,
uhd_tx_streamer_send(tx_streamer, buffs_ptr, samps_per_buff, &md, 0.1, &num_samps_sent)
)
@@ -216,6 +216,9 @@ int main(int argc, char* argv[]){
}
}
+ free_buff:
+ free(buff);
+
free_tx_streamer:
if(verbose){
fprintf(stderr, "Cleaning up TX streamer.\n");