You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Joe Schaefer <jo...@sunstarsys.com> on 2001/08/09 21:51:42 UTC
Re: Apache::Upload bug?
"Jeffrey Hartmann" <pe...@lefty.org> writes:
> After much tracing I found that the problem occurs in the command "my
> $fh = $file->fh;" where Apache::Upload dup()'s the filehandle and
> passed the duplicate to the perl script. Then when the program exits
> the perl script still has an open filehandle to that file. I fixed my
> problem by adding a "close $$fh;" to my program which closed the
> duplicate filehandle.
You have hit the nail on the head; the refcount for $$fh is too high.
I see the problem with apache1.3.19 + modperl 1.25 + perl 5.6.1,
but I don't know if the same holds for earlier versions.
It appears that the C code generated by xsubpp is the culprit, but I'm
not exactly sure about this.
In the meantine, try inserting the following line at the top of the
CLEANUP: section of ApacheUpload_fh in Request.xs:
SvREFCNT_dec(SvRV(ST(0))); /* ~ line 523 in Request.xs */
It seems to do the trick for single file uploads. Please let us
know if this fixes the problem for you.
> Now I'm not sure if this is a bug or if it's supposed to be like that,
> but the documentation makes it sound like it gives you the actually
> filehandle of the tempfile, and not a copy. I just assumed that it
> would be closed by Apache::Upload when the request was finished.
The duping behavior is desirable, but the filehandle remaining open
is definitely a bug; and it may have been around for quite a while.
Thanks a bunch for fleshing it out.
--
Joe Schaefer
[patch] Re: Apache::Upload bug?
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:
> In the meantine, try inserting the following line at the top of the
> CLEANUP: section of ApacheUpload_fh in Request.xs:
>
> SvREFCNT_dec(SvRV(ST(0))); /* ~ line 523 in Request.xs */
>
It looks to me like the stub code in perl's ExtUtils/typemap for T_IN
is causing the inflated refcount. Here's a patch that overrides T_IN;
it also cleans up the "Apache::Upload" symbol table a little earlier
than the original code does. Will commit if there's no objections.
% cvs diff
cvs server: Diffing .
Index: typemap
===================================================================
RCS file: /home/cvs/httpd-apreq/typemap,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 typemap
--- typemap 1999/01/27 01:33:20 1.1.1.1
+++ typemap 2001/08/10 14:35:41
@@ -3,8 +3,20 @@
Apache::Upload T_PTROBJ
Apache T_APACHEOBJ
const char * T_PV
+ApreqInputStream T_APREQIN
OUTPUT
+
+T_APREQIN
+ {
+ GV *gv = newGVgen("$Package");
+ if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) )
+ sv_setsv($arg, sv_bless(newRV_noinc((SV*)gv),
+ gv_stashpv("$Package",1)));
+ else
+ $arg = &PL_sv_undef;
+ (void)hv_delete(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), G_DISCARD);
+ }
T_APACHEOBJ
sv_setref_pv($arg, \"${ntype}\", (void*)$var);
cvs server: Diffing Cookie
cvs server: Diffing Request
Index: Request/Request.xs
===================================================================
RCS file: /home/cvs/httpd-apreq/Request/Request.xs,v
retrieving revision 1.25
diff -u -r1.25 Request.xs
--- Request/Request.xs 2001/06/29 19:13:17 1.25
+++ Request/Request.xs 2001/08/10 14:35:41
@@ -109,7 +109,7 @@
#define ApacheUpload_tempname(upload) upload->tempname
#ifdef PerlIO
-typedef PerlIO * InputStream;
+typedef PerlIO * ApreqInputStream;
/* XXX: or should this be #ifdef PERL_IMPLICIT_SYS ? */
#ifdef WIN32
@@ -125,7 +125,7 @@
#else /*PerlIO not defined*/
-typedef FILE * InputStream;
+typedef FILE * ApreqInputStream;
#define PerlIO_importFILE(fp,flags) fp
#define PerlIO_write(a,b,c) fwrite((b),1,(c),(a))
@@ -256,14 +256,6 @@
SvMAGIC(SvRV(sv))->mg_ptr = (char *)req->r;
}
-static void apreq_close_handle(void *data)
-{
- GV *handle = (GV*)data;
- (void)hv_delete(GvSTASH(handle),
- GvNAME(handle), GvNAMELEN(handle), G_DISCARD);
-}
-
-
#ifdef CGI_COMPAT
static void register_uploads (ApacheRequest *req) {
ApacheUpload *upload;
@@ -505,7 +497,7 @@
PROTOTYPES: DISABLE
-InputStream
+ApreqInputStream
ApacheUpload_fh(upload)
Apache::Upload upload
@@ -530,9 +522,7 @@
if (upload->req->parsed)
PerlIO_seek(fp, 0, 0);
- IoIFP(GvIOn((GV*)SvRV(ST(0)))) = fp;
- ap_register_cleanup(upload->req->r->pool, (void*)SvRV(ST(0)),
- apreq_close_handle, ap_null_cleanup);
+ IoIFP(io) = fp;
}
long
--
Joe Schaefer