summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaechul Lee <jcsing.lee@samsung.com>2023-09-20 11:27:13 +0900
committerJaechul Lee <jcsing.lee@samsung.com>2023-09-20 16:51:14 +0900
commitc4e2afc57d6de0f58843319734739b50f5417135 (patch)
treeaf533265b7737b84bfaf9b86e2e84abd5f8ce44a
parentd73c2ca10ae92822b9d38f4592be73d2cf9b325f (diff)
downloadaudio-hal-emul-tizen.tar.gz
audio-hal-emul-tizen.tar.bz2
audio-hal-emul-tizen.zip
checker said "strerror makes no guaranteee of thread safety. Use strerror_r function instead." In addition to this, coverity found the possibility of the resource leak [Version] 0.1.21 [Issue Type] SVACE Change-Id: I1293c655a8f973ef3d45b50fc6093154c9007436 Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
-rw-r--r--packaging/audio-hal-emul.spec2
-rw-r--r--tizen-audio-file.c24
-rw-r--r--tizen-audio-glue.c10
3 files changed, 26 insertions, 10 deletions
diff --git a/packaging/audio-hal-emul.spec b/packaging/audio-hal-emul.spec
index 3d68631..f61c198 100644
--- a/packaging/audio-hal-emul.spec
+++ b/packaging/audio-hal-emul.spec
@@ -1,6 +1,6 @@
Name: audio-hal-emul
Summary: TIZEN Audio HAL for Emulator
-Version: 0.1.20
+Version: 0.1.21
Release: 0
Group: System/Libraries
License: Apache-2.0
diff --git a/tizen-audio-file.c b/tizen-audio-file.c
index 1ad1488..5091028 100644
--- a/tizen-audio-file.c
+++ b/tizen-audio-file.c
@@ -26,12 +26,24 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <errno.h>
#include <tizen-audio.h>
#include <tizen-audio-internal.h>
#include <hal/hal-common-interface.h>
#include <tizen-audio-file.h>
+#define AUDIO_LOG_ERROR_WITH_STDERR(msg) __print_std_error(__LINE__, #msg)
+
+static void __print_std_error(int line, char *msg)
+{
+ char e[256];
+
+ strerror_r(errno, e, sizeof(e));
+
+ AUDIO_LOG_ERROR("line(%d). %s. err(%s)", line, msg, e);
+}
+
audio_return_e audio_file_open(const char *type, const char *filename, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle)
{
FILE *f;
@@ -115,23 +127,23 @@ audio_return_e audio_file_avail(void *handle, uint32_t *avail)
cur = ftell(f);
if (cur < 0) {
- AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to get the current location");
return AUDIO_ERR_INTERNAL;
}
if (fseek(f, 0L, SEEK_END) < 0) {
- AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to seek with SEEK_END");
return AUDIO_ERR_INTERNAL;
}
end = ftell(f);
if (end < 0) {
- AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to get the end location");
return AUDIO_ERR_INTERNAL;
}
if (fseek(f, cur, SEEK_SET) < 0) {
- AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to seek with SEEK_SET");
return AUDIO_ERR_INTERNAL;
}
@@ -151,7 +163,7 @@ audio_return_e audio_file_write(void *handle, const void *buffer, uint32_t frame
ret = fwrite(buffer, sizeof(short), frames, f);
if (ret == 0) {
- AUDIO_LOG_ERROR("Failed to write(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to write");
return AUDIO_ERR_INTERNAL;
}
@@ -169,7 +181,7 @@ audio_return_e audio_file_read(void *handle, void *buffer, uint32_t frames)
ret = fread(buffer, sizeof(short), frames, f);
if (ret == 0) {
- AUDIO_LOG_ERROR("Failed to read(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to read");
return AUDIO_ERR_INTERNAL;
}
diff --git a/tizen-audio-glue.c b/tizen-audio-glue.c
index d2cb085..8b8ecf9 100644
--- a/tizen-audio-glue.c
+++ b/tizen-audio-glue.c
@@ -22,11 +22,9 @@ struct audio_interface_s {
audio_return_e audio_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle)
{
- struct audio_interface_s *interface = (struct audio_interface_s *)calloc(1, sizeof(struct audio_interface_s));
+ struct audio_interface_s *interface;
void *glue_handle = NULL;
- AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_RESOURCE);
-
AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_RESOURCE);
AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_RESOURCE);
AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_RESOURCE);
@@ -36,6 +34,12 @@ audio_return_e audio_open(void *audio_handle, const char *card, const char *devi
AUDIO_LOG_INFO("card(%s), device(%s), direction(%u), period_size(%u), periods(%u)",
card, device, direction, period_size, periods);
+ interface = (struct audio_interface_s *)calloc(1, sizeof(struct audio_interface_s));
+ if (!interface) {
+ AUDIO_LOG_INFO("Failed to allocate memory");
+ return AUDIO_ERR_INTERNAL;
+ }
+
if (!strcmp(card,"file")) {
interface->open = audio_file_open;
interface->start = audio_file_start;