diff --git a/src/main/tools/linux-sandbox-pid1.cc b/src/main/tools/linux-sandbox-pid1.cc index 2a3c48978fcbe8..b090ef99c52ff0 100644 --- a/src/main/tools/linux-sandbox-pid1.cc +++ b/src/main/tools/linux-sandbox-pid1.cc @@ -146,8 +146,17 @@ static int CreateTarget(const char *path, bool is_directory) { } // Create the parent directory. - if (CreateTarget(dirname(strdupa(path)), true) < 0) { - DIE("CreateTarget %s", dirname(strdupa(path))); + { + char *buf, *dir; + + if (!(buf = strdup(path))) DIE("strdup"); + + dir = dirname(buf); + if (CreateTarget(dir, true) < 0) { + DIE("CreateTarget %s", dir); + } + + free(buf); } if (is_directory) {