Permalink
Browse files

wrapper: proper free if exec and die fail

This is unlikely, but we might as well fix it so that we are not
freeing things we did not allocate.

A development version of 1d62824 (wrapper: learn the "-l" option,
2011-03-18) worked something like this, but it was lost to reworking
before the final commit.

valgrind will point out of the problem if we arrange for die_errno
to not actually exit.
  • Loading branch information...
1 parent d847e84 commit ac6b09e4fced3f9c58de326422ed521b609934d0 @ChrisJohnsen committed Mar 29, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 reattach-to-user-namespace.c
@@ -125,10 +125,10 @@ int main(int argc, char *argv[]) {
}
int arg = 1;
- char **newargs = argv+arg;
- const char *file = argv[arg++];
+ char **newargs = NULL;
+ const char *file = argv[arg];
if (!strcmp(file, "-l")) {
- file = argv[arg];
+ file = argv[++arg];
/*
* For their argv[0], take the bit of file after the
* last slash (the whole thing if there is no slash
@@ -153,7 +153,7 @@ int main(int argc, char *argv[]) {
newargs[arg-ofs] = NULL;
}
- if (execvp(file, newargs) < 0)
+ if (execvp(file, newargs ? newargs : argv+arg) < 0)
die_errno(3, "execv failed");
if (newargs) {

0 comments on commit ac6b09e

Please sign in to comment.