aboutsummaryrefslogtreecommitdiffhomepage
path: root/proc.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-01-31 18:06:20 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-01-31 18:06:20 -0800
commitbeece6a8288614e7dda22e7994e679878ec971de (patch)
tree505e3e6323440f0617915cbb51df0916aeac6025 /proc.cpp
parent207ab2aa5bff997a32971f4e5c4d79ebfd644764 (diff)
Clean up how argv is stored in process_t
Diffstat (limited to 'proc.cpp')
-rw-r--r--proc.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/proc.cpp b/proc.cpp
index c7f49bd3..3ca10e2d 100644
--- a/proc.cpp
+++ b/proc.cpp
@@ -183,6 +183,31 @@ void job_free( job_t * j )
halloc_free( j );
}
+void process_t::free_argv(void) {
+ if (argv_array != NULL) {
+ for (size_t i = 0; argv_array[i] != NULL; i++) {
+ delete [] argv_array[i];
+ }
+ delete [] argv_array;
+ }
+ argv_array = NULL;
+}
+
+void process_t::set_argv(const wcstring_list_t &argv) {
+ /* Get rid of the old argv */
+ free_argv();
+
+ /* Allocate our null-terminated array of null-terminated strings */
+ size_t i, count = argv.size();
+ argv_array = new wchar_t* [count + 1];
+ for (i=0; i < count; i++) {
+ const wcstring &str = argv.at(i);
+ argv_array[i] = new wchar_t [1 + str.size()];
+ wcscpy(argv_array[i], str.c_str());
+ }
+ argv_array[i] = NULL;
+}
+
void proc_destroy()
{
delete event.arguments;