diff --git a/ede-launch/ede-launch.cpp b/ede-launch/ede-launch.cpp index f0be089..3a14801 100644 --- a/ede-launch/ede-launch.cpp +++ b/ede-launch/ede-launch.cpp @@ -167,13 +167,18 @@ static int start_child_process(const char* cmd) { close(err[1]); break; default: - /* perent */ + /* parent */ close(in[0]); close(out[1]); close(err[1]); break; } + /* cleanup when returns from the child */ + for(int i = 0; params[i]; i++) + free(params[i]); + free(params); + int status, ret; errno = 0; if(waitpid(pid, &status, 0) < 0) { @@ -326,48 +331,45 @@ static int start_dialog(int argc, char** argv) { } int main(int argc, char** argv) { - if(argc == 1) + if(argc <= 1) return start_dialog(argc, argv); + /* do not see possible flags as commands */ + if(argv[1][0] == '-') { + help(); + return 0; + } + String args; + unsigned int alen; - if(argc > 1) { - /* do not see possible flags as commands */ - if(argv[1][0] == '-') { - help(); - return 0; - } + for(int i = 1; i < argc; i++) { + args += argv[i]; + args += ' '; + } - String args; - unsigned int alen; - for(int i = 1; i < argc; i++) { - args += argv[i]; - args += ' '; - } + alen = args.length(); - alen = args.length(); + /* remove start/ending quotes and spaces */ + if((args[0] == '"') || isspace(args[0]) || (args[alen - 1] == '"') || isspace(args[alen - 1])) { + int i; + char *copy = strdup(args.c_str()); + char *ptr = copy; - /* remove start/ending quotes and spaces */ - if((args[0] == '"') || isspace(args[0]) || (args[alen - 1] == '"') || isspace(args[alen - 1])) { - int i; - char *copy = strdup(args.c_str()); - char *ptr = copy; + /* remove ending first */ + for(i = (int)alen - 1; i > 0 && (ptr[i] == '"' || isspace(ptr[i])); i--) + ; - /* remove ending first */ - for(i = (int)alen - 1; i > 0 && (ptr[i] == '"' || isspace(ptr[i])); i--) - ; + ptr[i + 1] = 0; - ptr[i + 1] = 0; + /* remove then starting */ + for(; *ptr && (*ptr == '"' || isspace(*ptr)); ptr++) + ; - /* remove then starting */ - for(; *ptr && (*ptr == '"' || isspace(*ptr)); ptr++) - ; - - start_child(ptr); - free(copy); - } else { - start_child(args.c_str()); - } + start_child(ptr); + free(copy); + } else { + start_child(args.c_str()); } return 0;