summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-11-29 02:06:42 +0100
committerRobin Gareus <robin@gareus.org>2018-11-29 02:06:42 +0100
commit1759d1c9c9a487b69542bd0cebddd07d99fafbc7 (patch)
treebdb79b819f9690402225110808e9b17f122f62ce /libs
parent6fc2804414739d079e6c8798906887ecea152956 (diff)
Fix a tiny memory-leak when calling vfork
Diffstat (limited to 'libs')
-rw-r--r--libs/pbd/pbd/system_exec.h3
-rw-r--r--libs/pbd/system_exec.cc15
2 files changed, 16 insertions, 2 deletions
diff --git a/libs/pbd/pbd/system_exec.h b/libs/pbd/pbd/system_exec.h
index 5e543e76ae..1e36c3df9f 100644
--- a/libs/pbd/pbd/system_exec.h
+++ b/libs/pbd/pbd/system_exec.h
@@ -231,6 +231,9 @@ class LIBPBD_API SystemExec
void make_wargs(char **);
#else
pid_t pid;
+# ifndef NO_VFORK
+ char **argx;
+# endif
#endif
void init ();
pthread_mutex_t write_lock;
diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc
index 26f50146c8..6f86e5edb9 100644
--- a/libs/pbd/system_exec.cc
+++ b/libs/pbd/system_exec.cc
@@ -171,6 +171,8 @@ SystemExec::init ()
stdoutP[0] = stdoutP[1] = INVALID_HANDLE_VALUE;
stderrP[0] = stderrP[1] = INVALID_HANDLE_VALUE;
w_args = NULL;
+#elif !defined NO_VFORK
+ argx = NULL;
#endif
}
@@ -356,6 +358,14 @@ SystemExec::~SystemExec ()
}
#ifdef PLATFORM_WINDOWS
if (w_args) free(w_args);
+#elif !defined NO_VFORK
+ if (argx) {
+ /* argx[0 .. 8] are fixed parameters to vfork-exec-wrapper */
+ for (int i = 0; i < 9; ++i) {
+ free (argx[i]);
+ }
+ free (argx);
+ }
#endif
pthread_mutex_destroy(&write_lock);
}
@@ -911,8 +921,9 @@ SystemExec::start (int stderr_mode, const char *vfork_exec_wrapper)
*/
int argn = 0;
for (int i=0;argp[i];++i) { argn++; }
- char **argx = (char **) malloc((argn + 10) * sizeof(char *));
- argx[0] = strdup(vfork_exec_wrapper); // XXX
+
+ argx = (char **) malloc((argn + 10) * sizeof(char *));
+ argx[0] = strdup(vfork_exec_wrapper);
#define FDARG(NUM, FDN) \
argx[NUM] = (char*) calloc(6, sizeof(char)); snprintf(argx[NUM], 6, "%d", FDN);