From fbb974d6a6eda4d3ed1fc6975e2b0dd77b72f3dd Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 28 Jul 2015 15:57:42 +0900 Subject: [PATCH] libstorage: Do not use thread-unsafe function and code clearance strerror() is not safety on multi thread environment. Add initialize input buffer. Signed-off-by: Jiyoung Yun Change-Id: I159b6a2162ef73e1dd337910a5b2e9a80e1354bd --- src/statvfs.c | 14 ++++++++------ src/storage-sdcard.c | 2 +- src/storage.c | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index 81d323f..ff93b21 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -192,7 +192,7 @@ static int load_config(struct parse_result *result, void *user_data) value = result->value; if (info->check_size > 0 && check_size < 0) - check_size = (storage_info.total_size < info->check_size)? 1 : 0; + check_size = (storage_info.total_size < info->check_size) ? 1 : 0; if (MATCH(name, "CHECK_SIZE")) info->check_size = atoi(value); else if (check_size == 0 && MATCH(name, "RESERVE")) @@ -223,6 +223,8 @@ static int get_memory_size(const char *path, struct statvfs_32 *buf) if (ret) return -errno; + memset(buf, 0, sizeof(struct statvfs_32)); + buf->f_bsize = s.f_bsize; buf->f_frsize = s.f_frsize; buf->f_blocks = (unsigned long)s.f_blocks; @@ -303,17 +305,17 @@ API int storage_get_internal_memory_size64(struct statvfs *buf) return 0; } -static int mount_check(const char* path) +static int mount_check(const char *path) { int ret = false; - struct mntent* mnt; - const char* table = "/etc/mtab"; - FILE* fp; + struct mntent *mnt; + const char *table = "/etc/mtab"; + FILE *fp; fp = setmntent(table, "r"); if (!fp) return ret; - while ((mnt=getmntent(fp))) { + while ((mnt = getmntent(fp))) { if (!strcmp(mnt->mnt_dir, path)) { ret = true; break; diff --git a/src/storage-sdcard.c b/src/storage-sdcard.c index 65747af..fc02c6b 100755 --- a/src/storage-sdcard.c +++ b/src/storage-sdcard.c @@ -93,7 +93,7 @@ static const char *sdcard_get_root(void) return SDCARD_PATH; } -static void sdcard_state_cb(keynode_t* key, void* data) +static void sdcard_state_cb(keynode_t *key, void *data) { struct storage_cb_info *cb_info; dd_list *elem; diff --git a/src/storage.c b/src/storage.c index 480ef05..cbe34b5 100644 --- a/src/storage.c +++ b/src/storage.c @@ -88,7 +88,7 @@ API int storage_get_root_directory(int storage_id, char **path) *path = strdup(st->root()); if (!*path) { - _E("Failed to copy the root string : %s", strerror(errno)); + _E("Failed to copy the root string : %d", errno); return STORAGE_ERROR_OUT_OF_MEMORY; } @@ -131,7 +131,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p *path = strdup(temp); if (!*path) { - _E("Failed to copy the directory(%d) string : %s", type, strerror(errno)); + _E("Failed to copy the directory(%d) string : %d", type, errno); return STORAGE_ERROR_OUT_OF_MEMORY; } -- 2.7.4