Hi, I'm not sure this is a bug in the code, the comment or my thinking. So first try goes to r-devel... I find the following comment in X11_Open () (src/unix/X11/devX11.c): /* if we have to bail out with "error", then must free(dd) and free(xd) */ A couple lines down, there is: if (!strncmp(dsp, "png::", 5)) { FILE *fp; #ifndef HAVE_PNG error("No png support in this version of R"); #endif if (!(fp = R_fopen(R_ExpandFileName(dsp+5), "w"))) error("could not open PNG file `%s'", dsp+6); ... So what does the comment imply? If error jumps out to the toplevel without giving X11DeviceDriver a chance to free dd and xd, then this should be: if (!strncmp(dsp, "png::", 5)) { FILE *fp; #ifndef HAVE_PNG free (xd); free (dd); error("No png support in this version of R"); #endif if (!(fp = R_fopen(R_ExpandFileName(dsp+5), "w"))) { free (xd); free (dd); error("could not open PNG file `%s'", dsp+6); } There are a couple more error()s without free()s. The memory leak isn't big, I'd still appreciate it if you clarify who should do the free(). Thanks, -tom -- mailto:tov@ece.cmu.edu (Tom Vogels) Tel: (412) 268-6638 FAX: -3204 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 14 Feb 2001, Thomas Vogels wrote:> > Hi, I'm not sure this is a bug in the code, the comment or my > thinking. So first try goes to r-devel... I find the following > comment in X11_Open () (src/unix/X11/devX11.c): > > /* if we have to bail out with "error", then must free(dd) and free(xd) */ > > A couple lines down, there is: > > if (!strncmp(dsp, "png::", 5)) { > FILE *fp; > #ifndef HAVE_PNG > error("No png support in this version of R"); > #endif > if (!(fp = R_fopen(R_ExpandFileName(dsp+5), "w"))) > error("could not open PNG file `%s'", dsp+6); > ... > > So what does the comment imply? If error jumps out to the toplevel > without giving X11DeviceDriver a chance to free dd and xd, then this > should be:[...] Well, the thinking was that people would not be trying to use facilities on systems where they had not bothered to implement them, so what problem was a small memory leak? They would only do it once, ever .... In these cases it would be better to give a warning and return FALSE, when the normal return mechanism will free xd and then dd. I will alter it to that when I have tested it out. BDR -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Date: 15 Feb 2001 09:29:42 -0500 > From: Thomas Vogels > Subject: Re: [Rd] who frees dd and xd in X11_Open? > > Prof Brian Ripley writes: > > > On 14 Feb 2001, Thomas Vogels wrote: > > > > > > > > Hi, I'm not sure this is a bug in the code, the comment or my > > > thinking. So first try goes to r-devel... I find the following > > > comment in X11_Open () (src/unix/X11/devX11.c): > > > > > > /* if we have to bail out with "error", then must free(dd) and free(xd) */ > > > > > > A couple lines down, there is: > > > > > > if (!strncmp(dsp, "png::", 5)) { > > > FILE *fp; > > > #ifndef HAVE_PNG > > > error("No png support in this version of R"); > > > #endif > > > if (!(fp = R_fopen(R_ExpandFileName(dsp+5), "w"))) > > > error("could not open PNG file `%s'", dsp+6); > > > ... > > > > > > So what does the comment imply? If error jumps out to the toplevel > > > without giving X11DeviceDriver a chance to free dd and xd, then this > > > should be: > > > > [...] > > > > Well, the thinking was that people would not be trying to use facilities > > on systems where they had not bothered to implement them, so what problem > > was a small memory leak? They would only do it once, ever .... > > uh, I guess I screwed up the example. Even more lines down, there is > no free accompanying the error ("could not open PNG file ..."). That > can happen more often and more memory would leak. But no, I wanted to > know this for another reason: I've played around with the X11 device > driver to implement a feature that allows me to embed the device into > another window. Opening and closing of x11()'s can happen often > during the execution of the program. But I'm still not interested in > the memory leak issue per se. > > I've seen a segfault or two (not in the regular code) and right now I > blame it on Xevents arriving after the device is shut down. Now all > of a sudden the calls to free become very interesting. As I said at > the beginning of the email, I wanted to simply understand the comment, > understand what should be going on, not criticize for it not being > followed. > > Although I got the question wrong, I guess, I got the right answer :-) > Thanks. > > Regards, > -tom > > > > > > In these cases it would be better to give a warning and return FALSE, when > > the normal return mechanism will free xd and then dd. I will alter it to > > that when I have tested it out. > >I don't know if it has something to do with this discussion, but it's probably worth reporting it. Under SunOS pul 5.8 Generic sun4u sparc SUNW,Ultra-5_10 R : Version 1.2.1 (2001-01-15) Fvwm95 Version 2.0.43a the window manager always crashes when I close an x11() device started within R. Adrian -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Date: Fri, 16 Feb 2001 09:04:45 +0100 > From: Adrian Trapletti <adrian@olsen.ch> I don't know if it has something to do with this discussion, but it's > probably worth reporting it. > > Under > SunOS pul 5.8 Generic sun4u sparc SUNW,Ultra-5_10 > R : Version 1.2.1 (2001-01-15) > Fvwm95 Version 2.0.43a > the window manager always crashes when I close an x11() device started > within R.This discussion is about png() and jpeg() devices. We've had other reports about FVWM, though. Why anyone would use FVWM95 on a system that comes with CDE is an interesting question, though.... -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- X11 window title setting in X11() Device (PR#11325)
- [PATCH] R ignores PATH_MAX and fails in long directories (PR#14228)
- Segmentation fault when using "plot" function
- RE: [PATCH] supporting non-NX/XD capable processors onx86_64 xenlinux
- file.copy() problems on WinNT (PR#1085)