LibC: Don't use ScopeGuard in exec
These ended up pulling `operator delete` which is not available when linking with gcc :^)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <BAN/Assert.h>
|
||||
#include <BAN/Debug.h>
|
||||
#include <BAN/ScopeGuard.h>
|
||||
#include <BAN/StringView.h>
|
||||
|
||||
#include <LibELF/AuxiliaryVector.h>
|
||||
@@ -444,13 +443,15 @@ static int exec_impl_shebang(FILE* fp, const char* pathname, char* const* argv,
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
BAN::ScopeGuard _1([buffer] { free(buffer); });
|
||||
|
||||
buffer = fgets(buffer, buffer_len, fp);
|
||||
fclose(fp);
|
||||
|
||||
if (buffer == nullptr)
|
||||
if (fgets(buffer, buffer_len, fp) == nullptr)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
const auto sv_trim_whitespace =
|
||||
[](BAN::StringView sv) -> BAN::StringView
|
||||
@@ -465,6 +466,7 @@ static int exec_impl_shebang(FILE* fp, const char* pathname, char* const* argv,
|
||||
BAN::StringView buffer_sv = buffer;
|
||||
if (buffer_sv.back() != '\n')
|
||||
{
|
||||
free(buffer);
|
||||
errno = ENOEXEC;
|
||||
return -1;
|
||||
}
|
||||
@@ -481,6 +483,7 @@ static int exec_impl_shebang(FILE* fp, const char* pathname, char* const* argv,
|
||||
|
||||
if (interpreter.empty())
|
||||
{
|
||||
free(buffer);
|
||||
errno = ENOEXEC;
|
||||
return -1;
|
||||
}
|
||||
@@ -495,10 +498,12 @@ static int exec_impl_shebang(FILE* fp, const char* pathname, char* const* argv,
|
||||
old_argc++;
|
||||
|
||||
const size_t extra_args = 1 + !argument.empty();
|
||||
char** new_argv = static_cast<char**>(malloc((extra_args + old_argc + 1) * sizeof(char*)));;
|
||||
char** new_argv = static_cast<char**>(malloc((extra_args + old_argc + 1) * sizeof(char*)));
|
||||
if (new_argv == nullptr)
|
||||
{
|
||||
free(buffer);
|
||||
return -1;
|
||||
BAN::ScopeGuard _2([new_argv] { free(new_argv); });
|
||||
}
|
||||
|
||||
new_argv[0] = const_cast<char*>(pathname);
|
||||
if (!argument.empty())
|
||||
@@ -509,7 +514,10 @@ static int exec_impl_shebang(FILE* fp, const char* pathname, char* const* argv,
|
||||
new_argv[extra_args + i] = argv[i];
|
||||
new_argv[extra_args + old_argc] = nullptr;
|
||||
|
||||
return exec_impl(interpreter.data(), new_argv, envp, true, shebang_depth + 1);
|
||||
int result = exec_impl(interpreter.data(), new_argv, envp, true, shebang_depth + 1);
|
||||
free(new_argv);
|
||||
free(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int execl_impl(const char* pathname, const char* arg0, va_list ap, bool has_env, bool do_path_resolution)
|
||||
|
||||
Reference in New Issue
Block a user