Skip to content

Commit

Permalink
wrapper: proper free if exec and die fail
Browse files Browse the repository at this point in the history
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
ChrisJohnsen committed Mar 29, 2011
1 parent d847e84 commit ac6b09e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions reattach-to-user-namespace.c
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit ac6b09e

Please sign in to comment.