[Rd] who frees dd and xd in X11_Open?

Thomas Vogels Thomas Vogels <tov@ece.cmu.edu>
14 Feb 2001 23:38:15 -0500


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._