From b2c5aeea0275bd4a5b6ab12ac903088afc00dc50 Mon Sep 17 00:00:00 2001 From: zawz Date: Fri, 28 Jan 2022 09:38:42 +0100 Subject: [PATCH] fix(exec): fix segfault on exec failure --- src/exec.cpp | 4 ++-- src/main.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 2521517..ff3f20d 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -260,10 +260,10 @@ int exec_process(std::string const& runtime, std::vector const& arg } catch(std::runtime_error& e) { - fclose(ffd); - unlink(fifopath.c_str()); if(pid != 0) kill(pid, SIGINT); + fclose(ffd); + unlink(fifopath.c_str()); throw e; } diff --git a/src/main.cpp b/src/main.cpp index 665df43..94f83b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,6 +139,8 @@ int main(int argc, char* argv[]) ctx = make_context(filecontents, file, parse_bash); if(is_exec) { + delete sh; + sh = nullptr; args.erase(args.begin()); return exec_process(shebang.substr(2), args, ctx); }