From: Jinhyung Jo Date: Wed, 23 Aug 2017 02:23:58 +0000 (+0900) Subject: appcmd: change argument from local to heap X-Git-Tag: accepted/tizen/4.0/unified/20170904.143511~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=658a001a3707f5c5ccbb98d6f861e52cfe33efa1;p=sdk%2Ftarget%2Fsdbd.git appcmd: change argument from local to heap Change-Id: I708ae784d24cbd5394d2787bf15b53b27ee33c16 Signed-off-by: Jinhyung Jo --- diff --git a/src/plugin.c b/src/plugin.c index fd6ceb8..2e257fe 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -212,6 +212,8 @@ static void request_async_cmd ( int cmd, parameters* in, int out_fd ) ret = default_plugin_async_proc ( cmd, in, out_fd ); } + release_parameters(in); + free(in); sdb_close(out_fd); } @@ -229,21 +231,31 @@ static int create_async_proc_thread( int cmd, parameters* in ) sdb_thread_t t; int s[2]; - if( sdb_socketpair(s) ) { + if (sdb_socketpair(s)) { + release_parameters(in); + free(in); D("cannot create async proc socket pair\n"); return -1; } - async_param = ( async_parameter* ) malloc(sizeof(async_parameter)); - if( async_param == NULL ) fatal("cannot allocate async_parameter"); + async_param = (async_parameter*)malloc(sizeof(async_parameter)); + if (async_param == NULL) { + release_parameters(in); + free(in); + fatal("cannot allocate async_parameter"); + return -1; + } + async_param->cmd = cmd; async_param->in = in; async_param->out_fd = s[1]; - if(sdb_thread_create( &t, async_proc_bootstrap_func, async_param)){ + if (sdb_thread_create(&t, async_proc_bootstrap_func, async_param)) { free(async_param); sdb_close(s[0]); sdb_close(s[1]); + release_parameters(in); + free(in); D("cannot create async proc thread\n"); return -1; } @@ -396,27 +408,33 @@ int request_lock_state_to_plugin ( int lock_type ) // return -1 if failed to create async proc thread int request_appcmd_to_plugin ( const char* in_buf ) { - parameters in; + parameters* in; int fd; + in = (parameters*)malloc(sizeof(parameters)); + if (in == NULL) { + D("failed to allocate memory for the parameters\n"); + return -1; + } + if ( in_buf != NULL ) { - in.number_of_parameter = 1; - in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) ); - if (in.array_of_parameter == NULL) { + in->number_of_parameter = 1; + in->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) ); + if (in->array_of_parameter == NULL) { + free(in); D("failed to allocate memory for the parameter\n"); return -1; } - in.array_of_parameter[0].type = type_string; - in.array_of_parameter[0].v_string.length = strlen ( in_buf ); - in.array_of_parameter[0].v_string.data = strdup ( in_buf ); + in->array_of_parameter[0].type = type_string; + in->array_of_parameter[0].v_string.length = strlen ( in_buf ); + in->array_of_parameter[0].v_string.data = strdup ( in_buf ); } else { - in.number_of_parameter = 0; - in.array_of_parameter = NULL; + in->number_of_parameter = 0; + in->array_of_parameter = NULL; } - fd = create_async_proc_thread( PLUGIN_ASYNC_CMD_APPCMD_SERVICE, &in ); + fd = create_async_proc_thread( PLUGIN_ASYNC_CMD_APPCMD_SERVICE, in ); - release_parameters ( &in ); return fd; }