From 5f10611c16b4c5b7e68cba7d8f0252ebcdf2c750 Mon Sep 17 00:00:00 2001 From: Moritz Fischer Date: Sun, 27 Jan 2019 13:33:25 -0800 Subject: 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 --- host/examples/tx_samples_c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'host/examples') 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"); -- cgit v1.2.3