aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-11-13 20:27:47 +0000
committer_ov4 <ov4@ov4.org>2026-11-13 20:27:47 +0000
commit1660933d76b335048b7e9b3085d3e64f7af7b338 (patch)
treed389918a84bb176bec5313b586642be2b61f2b3a /src
parent111272567f63e4e5faf5a8e5b518c4e68d9d96bf (diff)
replace by malloc(), cleanup attribute, and removed unused .h
Diffstat (limited to 'src')
-rw-r--r--src/eval/eval_exe.cc16
-rw-r--r--src/util/string.cc5
2 files changed, 13 insertions, 8 deletions
diff --git a/src/eval/eval_exe.cc b/src/eval/eval_exe.cc
index 65e5a34..009fc1c 100644
--- a/src/eval/eval_exe.cc
+++ b/src/eval/eval_exe.cc
@@ -12,6 +12,7 @@
#include "lang_analysis/symbol_property.h"
#include "lang_analysis/parseline.h"
#include "util/io.h"
+#include "memory.h"
using namespace std;
@@ -34,7 +35,7 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
bool task_type_is_subshell = false;
const char *raw_input = nullptr;
- char **argv = nullptr;
+ __attribute__((cleanup(cleanup_free_argv))) char **argv = nullptr;
const char *unified_cmd_c = nullptr;
string unified_cmd, s_wrap_eliminated;
@@ -55,9 +56,13 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
// NB: remember to delete
argv = parseline(s);
- if (argv == nullptr || argv[0] == nullptr) { operator delete(argv); return 0; }
- if (exe_bultin_command(argv)) { operator delete(argv); return 0; }
+ // the compiler should free() it here
+ // if returns
+
+ if (argv == nullptr || argv[0] == nullptr) { return 0; }
+
+ if (exe_bultin_command(argv)) { return 0; }
unified_cmd = find_cmd(argv[0]);
unified_cmd_c = unified_cmd.c_str();
@@ -102,8 +107,7 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
}
// parent
-
- operator delete(argv);
+ free(argv);
argv = nullptr;
exit_required_pid = pid;
@@ -136,4 +140,4 @@ int eval_exe(const string &s, bool is_async, const T_lexer *lexer_instance, size
return 0;
}
-} \ No newline at end of file
+}
diff --git a/src/util/string.cc b/src/util/string.cc
index bec9638..794e5a1 100644
--- a/src/util/string.cc
+++ b/src/util/string.cc
@@ -1,6 +1,7 @@
#include "util/string.h"
#include <print>
+#include <cstdio>
using namespace std;
@@ -38,8 +39,8 @@ void string2argv(const vector<string> &v, char **argv)
*/
char **string2argv_alloc(const std::vector<std::string> &v)
{
- size_t size = argv_get_required_size(v);
- char **p = static_cast<char**>(operator new(size));
+ size_t size = argv_get_required_size(v) * sizeof(char);
+ char **p = (char**)malloc(size);
string2argv(v, p);
return p;
}