From atp at piskorski.com  Thu Oct 15 20:20:22 2009
From: atp at piskorski.com (atp at piskorski.com)
Date: Thu, 15 Oct 2009 20:20:22 +0200 (CEST)
Subject: [Rd] PR#14008,
	R segfault in fgets from do_system under high memory use
Message-ID: <20091015182022.915112831FE7@mail.pubhealth.ku.dk>

On this issue:

  http://bugs.r-project.org/cgi-bin/R/incoming?id=14008

Here's a small patch which fixes the problem:


$ svn diff src/main/sysutils.c src/unix/sys-unix.c
Index: src/main/sysutils.c
===================================================================
--- src/main/sysutils.c	(revision 49961)
+++ src/main/sysutils.c	(working copy)
@@ -260,6 +260,9 @@
 #else
     fp = popen(command, type);
 #endif
+    if (NULL == fp) {
+       error(_("popen failed with errno %i: %s"), errno, strerror(errno));
+    }
     return fp;
 }
 #endif /* HAVE_POPEN */
Index: src/unix/sys-unix.c
===================================================================
--- src/unix/sys-unix.c	(revision 49961)
+++ src/unix/sys-unix.c	(working copy)
@@ -270,6 +270,11 @@
 
	PROTECT(tlist);
	fp = R_popen(translateChar(STRING_ELT(CAR(args), 0)), x);
+        if (NULL == fp) {
+            UNPROTECT(1);
+            errorcall(call, _("R_popen returned NULL."));
+            return R_NilValue;
+        }
	 for (i = 0; fgets(buf, INTERN_BUFSIZE, fp); i++) {
	     read = strlen(buf);
	         if(read >= INTERN_BUFSIZE - 1)

-- 
Andrew Piskorski <atp at piskorski.com>
http://www.piskorski.com/



[Rd] PR#14008, R segfault in fgets from do_system under high memory use
atp at piskorski.com