summaryrefslogtreecommitdiffstats
path: root/qahw_api
diff options
context:
space:
mode:
authorErin Yan <xinyey@codeaurora.org>2018-05-29 11:12:55 +0800
committerErin Yan <xinyey@codeaurora.org>2018-06-05 12:15:13 +0800
commita093bf02e32163ba1dba780f9d10806528d38ba7 (patch)
treeee84632b5df64f3d293e245652560482616fd22f /qahw_api
parent338fd3bfcec34f190ce1540509ed79e744cb572c (diff)
downloadandroid_hardware_qcom_audio-a093bf02e32163ba1dba780f9d10806528d38ba7.tar.gz
android_hardware_qcom_audio-a093bf02e32163ba1dba780f9d10806528d38ba7.tar.bz2
android_hardware_qcom_audio-a093bf02e32163ba1dba780f9d10806528d38ba7.zip
hal: Check NULL pointer
FILE pointer could be NULL if open failed, need check it before close it. And it is good to set closed resource to NULL. CRs-fixed: 2249886 Change-Id: Ieb9ecb032f061f0895fcf83df5baf042b346b985
Diffstat (limited to 'qahw_api')
-rw-r--r--qahw_api/test/qahw_multi_record_test.c20
-rw-r--r--qahw_api/test/trans_loopback_test.c7
2 files changed, 20 insertions, 7 deletions
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index 2d9ee6a8..ed8fe406 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2015 The Android Open Source Project *
@@ -362,7 +362,7 @@ void *start_input(void *thread_param)
pthread_exit(0);
}
- FILE *fd_in_ts;
+ FILE *fd_in_ts = NULL;
if (params->timestamp_mode) {
if (*(params->timestamp_file_in))
fd_in_ts = fopen(params->timestamp_file_in, "w+");
@@ -457,8 +457,10 @@ void *start_input(void *thread_param)
}
data_sz += buffer_size;
}
- if (params->timestamp_mode)
+ if ((params->timestamp_mode) && fd_in_ts) {
fclose(fd_in_ts);
+ fd_in_ts = NULL;
+ }
/*Stopping sourcetracking thread*/
sourcetrack_done = 1;
@@ -470,15 +472,18 @@ void *start_input(void *thread_param)
fwrite(&hdr, 1, sizeof(hdr), fd);
free(buffer);
fclose(fd);
+ fd = NULL;
/* capture latency kpis if required */
if (kpi_mode) {
tCold = tsColdF.tv_sec*1000 - tsColdI.tv_sec*1000 +
tsColdF.tv_nsec/1000000 - tsColdI.tv_nsec/1000000;
- fread((void *) latencyBuf, 100, 1, fdLatencyNode);
- if (fdLatencyNode)
+ if (fdLatencyNode) {
+ fread((void *) latencyBuf, 100, 1, fdLatencyNode);
fclose(fdLatencyNode);
+ fdLatencyNode = NULL;
+ }
sscanf(latencyBuf, " %llu,%llu", &tsec, &tusec);
tCont = ((uint64_t)tsCont.tv_sec)*1000 - tsec*1000 + ((uint64_t)tsCont.tv_nsec)/1000000 - tusec/1000;
if (log_file != stdout) {
@@ -910,7 +915,10 @@ sourcetrack_error:
fprintf(log_file, "\n ADL: Done with hal record test \n");
if (log_file != stdout) {
fprintf(stdout, "\n ADL: Done with hal record test \n");
- fclose(log_file);
+ if (log_file) {
+ fclose(log_file);
+ log_file = NULL;
+ }
}
wakelock_acquired = request_wake_lock(wakelock_acquired, false);
return 0;
diff --git a/qahw_api/test/trans_loopback_test.c b/qahw_api/test/trans_loopback_test.c
index 2cb2a29c..f1d897aa 100644
--- a/qahw_api/test/trans_loopback_test.c
+++ b/qahw_api/test/trans_loopback_test.c
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -517,6 +517,11 @@ void process_loopback_data(void *ptr)
j++;
}
+ if (dev_path == NULL) {
+ fprintf(log_file, "NULL dev_path!");
+ continue;
+ }
+
if ((dev_path != NULL) && (switch_name != NULL))
fprintf(log_file,"devpath = %s, switch_name = %s \n",dev_path, switch_name);