From jeff.horner at vanderbilt.edu  Mon Sep  3 00:16:43 2007
From: jeff.horner at vanderbilt.edu (Jeffrey Horner)
Date: Sun, 02 Sep 2007 17:16:43 -0500
Subject: [Rd] Memory leak possible when redirecting R console
Message-ID: <46DB364B.9070204@vanderbilt.edu>

Hello,

To trigger the memory leak, an application embedding R will have printed 
  a vector element of size R_BUFSIZE or more to stdout, so long as the 
R_Outputfile pointer is NULL and R was compiled with vasprintf support. 
The leak is in Rcons_vprintf from printutils.c. It looks as though 
someone set up a fix for this but forgot a critical flag assignment when 
vasprintf() is called (vasprintf mallocs a buffer to print to, so it 
needs to be freed after use). Here's the fix:


Index: printutils.c
===================================================================
--- printutils.c        (revision 42743)
+++ printutils.c        (working copy)
@@ -658,8 +658,10 @@
      res = vsnprintf(buf, R_BUFSIZE, format, aq);
      va_end(aq);
  #ifdef HAVE_VASPRINTF
-    if(res >= R_BUFSIZE || res < 0)
+    if(res >= R_BUFSIZE || res < 0){
+       usedVasprintf = TRUE;
         vasprintf(&p, format, arg);
+    }
  #else
      if(res >= R_BUFSIZE) { /* res is the desired output length */
         usedRalloc = TRUE;

Best,

Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner



[Rd] Memory leak possible when redirecting R console
Jeffrey Horner