libstorage: Do not use thread-unsafe function and code clearance 15/44815/2
authorJiyoung Yun <jy910.yun@samsung.com>
Tue, 28 Jul 2015 06:57:42 +0000 (15:57 +0900)
committerJiyoung Yun <jy910.yun@samsung.com>
Tue, 28 Jul 2015 07:26:06 +0000 (16:26 +0900)
strerror() is not safety on multi thread environment.
Add initialize input buffer.

Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
Change-Id: I159b6a2162ef73e1dd337910a5b2e9a80e1354bd

src/statvfs.c
src/storage-sdcard.c
src/storage.c

index 81d323f..ff93b21 100644 (file)
@@ -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 charpath)
+static int mount_check(const char *path)
 {
        int ret = false;
-       struct mntentmnt;
-       const chartable = "/etc/mtab";
-       FILEfp;
+       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;
index 65747af..fc02c6b 100755 (executable)
@@ -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;
index 480ef05..cbe34b5 100644 (file)
@@ -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;
        }