ret = default_plugin_async_proc ( cmd, in, out_fd );
}
+ release_parameters(in);
+ free(in);
sdb_close(out_fd);
}
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;
}
// 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;
}