[Sumover-dev] [svn commit] r4226 - rat/trunk

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Fri Jul 25 10:37:38 BST 2008


Author: douglask
Date: Fri Jul 25 10:37:35 2008
New Revision: 4226

Modified:
   rat/trunk/process.c

Log:
With both the xmalloc and xfree calls for the args pointer array being performed in the forked child, the token argument is no longer being corrupted.

The bandaid xstrdup(token[i]) fix in the previous patch would fail misserably with a glib assembler backtrace on x86-64 linux (but not 32bit).

Using Valgrind, everything looks fine now.


Modified: rat/trunk/process.c
==============================================================================
--- rat/trunk/process.c	(original)
+++ rat/trunk/process.c	Fri Jul 25 10:37:35 2008
@@ -95,32 +95,33 @@
 	}
         /* Fork off the sub-process... */
         *pid = fork();
-        char **args = xmalloc((2 * num_tokens) + argc + 4);
-        int numargs=0;
         if (*pid == -1) {
                 perror("Cannot fork");
                 abort();
         } else if (*pid == 0) {
-			args[numargs++] = proc_name;
-			args[numargs++] = "-ctrl";
-			args[numargs++] = ctrl_addr;
-			for(i=0;i<num_tokens;i++) {
-				args[numargs++] = "-token";
-				args[numargs++] = xstrdup(token[i]);
-			}
-			for(i=0;i<argc;i++) {
-				args[numargs++] = argv[i];
-			}
-			args[numargs++] = NULL;
-			execvp( proc_name, args );
-		
-            perror("Cannot execute subprocess");
-            /* Note: this MUST NOT be exit() or abort(), since they affect the standard */
-            /* IO channels in the parent process (fork duplicates file descriptors, but */
-            /* they still point to the same underlying file).                           */
-            _exit(1);
+                char **args = xmalloc((2 * num_tokens) + argc + 4);
+                int numargs=0;
+
+                args[numargs++] = proc_name;
+                args[numargs++] = "-ctrl";
+                args[numargs++] = ctrl_addr;
+                for(i=0;i<num_tokens;i++) {
+                        args[numargs++] = "-token";
+                        args[numargs++] = token[i];
+                }
+                for(i=0;i<argc;i++) {
+                        args[numargs++] = argv[i];
+                }
+                args[numargs++] = NULL;
+                execvp( proc_name, args );
+	
+                perror("Cannot execute subprocess");
+                xfree(args);
+            	/* Note: this MUST NOT be exit() or abort(), since they affect the standard */
+  	        /* IO channels in the parent process (fork duplicates file descriptors, but */
+                /* they still point to the same underlying file).                           */
+                _exit(1);
         }
-        xfree(args);
 #endif
 #endif
 }



More information about the Sumover-dev mailing list