guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

system* memory leak


From: Kevin Ryde
Subject: system* memory leak
Date: Fri, 02 Apr 2004 08:06:29 +1000
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

        * simpos.c (scm_system_star): Fix execargv memory leak.

This occurs on any invocation, eg.

        (while #t (system* "true"))

The diff is bigger than it might be since I rearranged to combine the
parent and fork-error cases.

This is definitely a leak, but there seems to be a further problem
with sigaction afflicting system*, see other message.

--- simpos.c.~1.55.~    2004-03-31 11:57:03.000000000 +1000
+++ simpos.c    2004-04-01 07:09:02.000000000 +1000
@@ -158,12 +158,26 @@
       oldquit = scm_sigaction (sigquit, sig_ign, SCM_UNDEFINED);
       
       pid = fork ();
-      if (pid == -1)
-        SCM_SYSERROR;
-      else if (pid)
+      if (pid == 0)
         {
-          int wait_result;
-          int status;
+          /* child */
+          execvp (SCM_STRING_CHARS (SCM_CAR (args)), execargv);
+          scm_remember_upto_here_1 (args);
+          SCM_SYSERROR;
+          /* not reached.  */
+          return SCM_BOOL_F;
+        }
+      else
+        {
+          /* parent */
+          int wait_result, status, save_errno;
+
+          save_errno = errno;
+          free (execargv);
+          errno = save_errno;
+          if (pid == -1)
+            SCM_SYSERROR;
+
           SCM_SYSCALL (wait_result = waitpid (pid, &status, 0));
           if (wait_result == -1) SCM_SYSERROR;
           scm_sigaction (sigint, SCM_CAR (oldint), SCM_CDR (oldint));
@@ -171,14 +185,6 @@
           scm_remember_upto_here_2 (oldint, oldquit);
           return SCM_MAKINUM (0L + status);
         }
-      else
-        {
-          execvp (SCM_STRING_CHARS (SCM_CAR (args)), execargv);
-          scm_remember_upto_here_1 (args);
-          SCM_SYSERROR;
-          /* not reached.  */
-          return SCM_BOOL_F;
-        }
     }
   else
     SCM_WRONG_TYPE_ARG (1, SCM_CAR (args));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]