Fix static analyze issue 39/210439/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Jul 2019 06:30:49 +0000 (15:30 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Jul 2019 06:30:49 +0000 (15:30 +0900)
- Free unfreed memory.
- Clear memory before release which contains some critical information.

Change-Id: I10fc42edbc82585b54ecf731f0a05c04ba37d0f7
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
plugin/app2sd/server/app2sd_internals.c

index 4e2fc37..d545b8b 100644 (file)
@@ -134,8 +134,10 @@ int _app2sd_dmcrypt_setup_device(const char *pkgid,
                        "-c aes-cbc-lmk -s %d --align-payload=8 luksFormat %s",
                        passwd, DMCRYPT_ITER_TIME, DMCRYPT_KEY_LEN,
                        loopback_device);
+       memset(passwd, 0, strlen(passwd));
        free(passwd);
        ret = system(dmcrypt_setup_cmd);
+       memset(dmcrypt_setup_cmd, 0, BUF_SIZE);
        if (ret) {
                err_str = strerror_r(errno, err_buf, sizeof(err_buf));
                _E("Error setting up dmcrypt on app2sd file, error:%s, ret:%d",
@@ -1151,6 +1153,7 @@ int _app2sd_update_loopback_device_size(const char *pkgid,
                _E("remount failed");
                err_res = APP2EXT_ERROR_MOUNT_PATH;
        }
+       free(old_device_node);
 
        snprintf(app_mmc_path, sizeof(app_mmc_path),
                        "%s/.mmc", application_path);
@@ -1215,9 +1218,6 @@ int _app2sd_update_loopback_device_size(const char *pkgid,
        return APP2EXT_SUCCESS;
 
 FINISH_OFF:
-       if (old_device_node)
-               free(old_device_node);
-
        ret = _app2sd_dmcrypt_close_device(pkgid, uid);
        if (ret)
                _E("close dmcrypt device error(%d)", ret);