aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsugandhagupta <sugandha.gupta@ettus.com>2017-06-29 14:00:15 -0700
committerMartin Braun <martin.braun@ettus.com>2017-06-29 19:33:45 -0700
commit51aa599d0c42bfe9b9bcf5b465b1e0acc503156b (patch)
tree6c0b6ec627d91411a9ca4aefcd29f4f8f10047c7
parentd9bcf00f69313b6dd42346d6af340a1a9874ba9f (diff)
downloaduhd-51aa599d0c42bfe9b9bcf5b465b1e0acc503156b.tar.gz
uhd-51aa599d0c42bfe9b9bcf5b465b1e0acc503156b.tar.bz2
uhd-51aa599d0c42bfe9b9bcf5b465b1e0acc503156b.zip
examples/c-api: Fix invalid free of device_args
One does not simply free() stack / automatic variables. Please `man 3 strdup()`. Signed-off-by: Sugandha Gupta <sugandha.gupta@ettus.com> Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
-rw-r--r--host/examples/rx_samples_c.c7
-rw-r--r--host/examples/tx_samples_c.c11
2 files changed, 10 insertions, 8 deletions
diff --git a/host/examples/rx_samples_c.c b/host/examples/rx_samples_c.c
index d269e29b7..b453a684e 100644
--- a/host/examples/rx_samples_c.c
+++ b/host/examples/rx_samples_c.c
@@ -53,7 +53,7 @@ int main(int argc, char* argv[])
double freq = 500e6;
double rate = 1e6;
double gain = 5.0;
- char* device_args = "";
+ char* device_args = NULL;
size_t channel = 0;
char* filename = "out.dat";
size_t n_samples = 1000000;
@@ -105,6 +105,9 @@ int main(int argc, char* argv[])
}
}
+ if (!device_args)
+ device_args = strdup("");
+
// Create USRP
uhd_usrp_handle usrp;
fprintf(stderr, "Creating USRP with args \"%s\"...\n", device_args);
@@ -279,7 +282,7 @@ int main(int argc, char* argv[])
uhd_usrp_free(&usrp);
free_option_strings:
- if(strcmp(device_args,"")){
+ if(device_args) {
free(device_args);
}
if(custom_filename){
diff --git a/host/examples/tx_samples_c.c b/host/examples/tx_samples_c.c
index 333c7e820..6b120516b 100644
--- a/host/examples/tx_samples_c.c
+++ b/host/examples/tx_samples_c.c
@@ -57,7 +57,7 @@ int main(int argc, char* argv[]){
double freq = 2e9;
double rate = 1e6;
double gain = 0;
- char* device_args;
+ char* device_args = NULL;
size_t channel = 0;
uint64_t total_num_samps = 0;
bool verbose = false;
@@ -106,9 +106,9 @@ int main(int argc, char* argv[]){
fprintf(stderr, "Unable to set thread priority. Continuing anyway.\n");
}
- if (device_args == NULL){
- device_args = "";
- }
+ if (!device_args)
+ device_args = strdup("");
+
// Create USRP
uhd_usrp_handle usrp;
fprintf(stderr, "Creating USRP with args \"%s\"...\n", device_args);
@@ -249,9 +249,8 @@ int main(int argc, char* argv[]){
uhd_usrp_free(&usrp);
free_option_strings:
- if(device_args != NULL){
+ if(device_args)
free(device_args);
- }
fprintf(stderr, (return_code ? "Failure\n" : "Success\n"));