struct lib_list_t *lib = us_inst->lib_inst_list;
struct app_list_t *app = us_inst->app_inst_list;
- char *p, *resolved;
+ char *p;
uint32_t total_maps_count = 0;
uint32_t total_len = sizeof(total_maps_count) + sizeof(*lib_maps_message);
- char real_path_buf[PATH_MAX];
/* Add preload type size */
total_len += sizeof(uint8_t);
}
while (app != NULL) {
- p = app->app->exe_path;
- resolved = realpath((const char *)p, real_path_buf);
+ const char *exe_path = app->app->exe_path;
+ char *resolved = realpath(exe_path, NULL);
if (resolved != NULL) {
/* Add to total_len entry size: path length, path itself with \0 */
- total_len += sizeof(uint32_t) + strlen(real_path_buf) + 1;
+ total_len += sizeof(uint32_t) + strlen(resolved) + 1;
total_maps_count++;
LOGI("app #%u <%s>\n", total_maps_count, resolved);
+ free(resolved);
} else {
- LOGE("cannot resolve bin path <%s>\n", p);
+ LOGE("cannot resolve bin path <%s>\n", exe_path);
}
app = (struct app_list_t *)app->next;
app = us_inst->app_inst_list;
while (app != NULL) {
- resolved = realpath(app->app->exe_path, real_path_buf);
- if (resolved != NULL)
- pack_path_with_len(p, real_path_buf);
+ char *resolved = realpath(app->app->exe_path, NULL);
+ if (resolved != NULL) {
+ pack_path_with_len(p, resolved);
+ free(resolved);
+ }
app = (struct app_list_t *)app->next;
}
struct lib_list_t *lib = us_inst->lib_inst_list;
struct app_list_t *app = us_inst->app_inst_list;
uint32_t total_maps_count = 0;
- char real_path_buf[PATH_MAX];
- char *resolved, *p;
+ char *p;
FILE *preload_p;
preload_p = fopen(PRELOAD_ADD_BIN, "w");
}
while (app != NULL) {
- resolved = realpath((const char *)app->app->exe_path, real_path_buf);
+ char *resolved = realpath(app->app->exe_path, NULL);
if (resolved != NULL) {
total_maps_count++;
fwrite(resolved, strlen(resolved) + 1, 1, preload_p);
fflush(preload_p);
LOGI("app #%u <%s>\n", total_maps_count, resolved);
+ free(resolved);
}
app = (struct app_list_t *)app->next;
{
struct app_list_t *app = us_inst->app_inst_list;
uint32_t total_maps_count = 0;
- char real_path_buf[PATH_MAX];
char *to_write;
FILE *file;
break;
}
- to_write = realpath((const char *)app->app->exe_path,
- real_path_buf);
+ to_write = realpath(app->app->exe_path, NULL);
if (to_write != NULL) {
total_maps_count++;
fwrite(to_write, strlen(to_write) + 1, 1, file);
LOGI("app #%u <%s>\n", total_maps_count,
to_write);
+ free(to_write);
}
fclose(file);
break;
int process_msg_get_real_path(struct msg_buf_t *msg)
{
const char *file_path = NULL;
- char buf[PATH_MAX];
- char *resolved_path;
+ char *resolved_path = NULL;
enum ErrorCode err_code = ERR_UNKNOWN;
uint32_t response_len = 0;
}
/* resolve file path */
- resolved_path = realpath(file_path, buf);
+ resolved_path = realpath(file_path, NULL);
LOGI("NMSG_GET_REAL_PATH resolved path <%s>\n", resolved_path);
if (resolved_path == NULL) {
LOGE("NMSG_GET_REAL_PATH error: cannot resolve path <%s>\n",
goto send_ack;
send_fail:
+ free(resolved_path);
+ resolved_path = NULL;
response_len = 0;
- resolved_path = "";
+
send_ack:
- /* success */
sendACKToHost(NMSG_GET_REAL_PATH, err_code, resolved_path, response_len);
+ free(resolved_path);
return -(err_code != ERR_NO);
}
return 0;
}
-static char *dereference_tizen_exe_path(const char *path, char *resolved);
+static char *dereference_tizen_exe_path(const char *path);
int is_same_app_process(char* appPath, int pid)
{
char buf[BUFFER_MAX];
char cmdPath[PATH_MAX];
char tPath[PATH_MAX];
- char buf_res[PATH_MAX];
- char tPath_res[PATH_MAX];
strncpy(tPath, appPath, PATH_MAX - 1);
tlen = strlen(tPath);
buf[tlen - 4] = '\0';
}
- dereference_tizen_exe_path(buf, buf_res);
- dereference_tizen_exe_path(tPath, tPath_res);
+ char *buf_res = dereference_tizen_exe_path(buf);
+ if (buf_res == NULL)
+ goto out;
+
+ char *tPath_res = dereference_tizen_exe_path(tPath);
+ if (tPath_res == NULL)
+ goto free_buf_res;
if(strcmp(buf_res, tPath_res) == 0)
ret = 1;
- else
- ret = 0;
+
+ free(tPath_res);
+free_buf_res:
+ free(buf_res);
}
- fclose(fp);
+out:
+ fclose(fp);
return ret;
}
-static char *dereference_tizen_exe_path(const char *path, char *resolved)
+/*
+ * Returns a pointer to allocated buffer or NULL.
+ * The caller should deallocate this buffer using free()
+ */
+static char *dereference_tizen_exe_path(const char *path)
{
char *res = NULL;
char tmp_path[PATH_MAX];
- resolved[0] = 0;
//try resolve <path>.exe
snprintf(tmp_path, sizeof(tmp_path), "%s.exe", path);
- if ((res = realpath(tmp_path, resolved)) == NULL) {
+ if ((res = realpath(tmp_path, NULL)) == NULL) {
//try to resolve path <path>
- res = realpath(path, resolved);
+ res = realpath(path, NULL);
}
return res;