diff options
author | Nils Durner <durner@gnunet.org> | 2010-06-21 18:52:56 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2010-06-21 18:52:56 +0000 |
commit | bb8d1c3cb6c6282ff57b136cde287338388968f4 (patch) | |
tree | 770f0eb7707de4b5471db898023bcf21336c8010 /src | |
parent | 7e1c1e5fc38fe294e07de5053e7ac9979dd8c6b9 (diff) | |
download | gnunet-bb8d1c3cb6c6282ff57b136cde287338388968f4.tar.gz gnunet-bb8d1c3cb6c6282ff57b136cde287338388968f4.zip |
fix mem issues, add ".exe" extension to path (fixes #1570, thanks to LRN on #gnunet)
Diffstat (limited to 'src')
-rw-r--r-- | src/util/os_priority.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index bc4b66b55..b354ad995 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -370,22 +370,62 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) | |||
370 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); | 370 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); |
371 | _exit (1); | 371 | _exit (1); |
372 | #else | 372 | #else |
373 | char **arg; | 373 | char **arg, **non_const_argv; |
374 | unsigned int cmdlen; | 374 | unsigned int cmdlen; |
375 | char *cmd, *idx; | 375 | char *cmd, *idx; |
376 | STARTUPINFO start; | 376 | STARTUPINFO start; |
377 | PROCESS_INFORMATION proc; | 377 | PROCESS_INFORMATION proc; |
378 | int argcount = 0; | ||
379 | char *non_const_filename = NULL; | ||
380 | int filenamelen = 0; | ||
378 | 381 | ||
379 | cmdlen = 0; | 382 | /* Count the number of arguments */ |
383 | arg = argv; | ||
384 | while (*arg) | ||
385 | { | ||
386 | arg++; | ||
387 | argcount++; | ||
388 | } | ||
389 | |||
390 | /* Allocate a copy argv */ | ||
391 | non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1)); | ||
392 | |||
393 | /* Copy all argv strings */ | ||
394 | argcount = 0; | ||
380 | arg = argv; | 395 | arg = argv; |
381 | while (*arg) | 396 | while (*arg) |
382 | { | 397 | { |
398 | non_const_argv[argcount] = GNUNET_strdup (*arg); | ||
399 | arg++; | ||
400 | argcount++; | ||
401 | } | ||
402 | non_const_argv[argcount] = NULL; | ||
403 | |||
404 | /* Fix .exe extension */ | ||
405 | filenamelen = strlen (filename); | ||
406 | if (filenamelen <= 4 || stricmp (&filename[filenamelen - 4], ".exe") != 0) | ||
407 | { | ||
408 | non_const_filename = GNUNET_malloc (sizeof (char) * (filenamelen + 4 + 1)); | ||
409 | non_const_filename = strcpy (non_const_filename, non_const_argv[0]); | ||
410 | strcat (non_const_filename, ".exe"); | ||
411 | GNUNET_free (non_const_argv[0]); | ||
412 | non_const_argv[0] = non_const_filename; | ||
413 | } | ||
414 | else | ||
415 | non_const_filename = non_const_argv[0]; | ||
416 | |||
417 | /* Count cmd len */ | ||
418 | cmdlen = 1; | ||
419 | arg = non_const_argv; | ||
420 | while (*arg) | ||
421 | { | ||
383 | cmdlen = cmdlen + strlen (*arg) + 3; | 422 | cmdlen = cmdlen + strlen (*arg) + 3; |
384 | arg++; | 423 | arg++; |
385 | } | 424 | } |
386 | 425 | ||
426 | /* Allocate and create cmd */ | ||
387 | cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); | 427 | cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); |
388 | arg = argv; | 428 | arg = non_const_argv; |
389 | while (*arg) | 429 | while (*arg) |
390 | { | 430 | { |
391 | idx += sprintf (idx, "\"%s\" ", *arg); | 431 | idx += sprintf (idx, "\"%s\" ", *arg); |
@@ -396,7 +436,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) | |||
396 | start.cb = sizeof (start); | 436 | start.cb = sizeof (start); |
397 | 437 | ||
398 | if (!CreateProcess | 438 | if (!CreateProcess |
399 | (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start, | 439 | (non_const_filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start, |
400 | &proc)) | 440 | &proc)) |
401 | { | 441 | { |
402 | SetErrnoFromWinError (GetLastError ()); | 442 | SetErrnoFromWinError (GetLastError ()); |
@@ -409,6 +449,10 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) | |||
409 | CloseHandle (proc.hThread); | 449 | CloseHandle (proc.hThread); |
410 | GNUNET_free (cmd); | 450 | GNUNET_free (cmd); |
411 | 451 | ||
452 | while (argcount > 0) | ||
453 | GNUNET_free (non_const_argv[--argcount]); | ||
454 | GNUNET_free (non_const_argv); | ||
455 | |||
412 | return proc.dwProcessId; | 456 | return proc.dwProcessId; |
413 | #endif | 457 | #endif |
414 | } | 458 | } |