Ok, for a the last couple days I've been searching out a problem I've been
having with Apache::Upload and Image::Magick.
The code consists mainly of::
@upload = $r->upload;
foreach my $file (@upload)
{
my $fh = $file->fh;
# There's some .ext checking here to get $type and some renaming.
my $i = Image::Magick->new(magick=>$type);
$err = $i->ReadImage(file=>$$fh);
$i->Set(magick=>$type);
$err = $i->WriteImage(filename=>$filename));
warn "$err" if "$err";
undef $i;
}
Now the main problem was that when the request was over the temp file
Apache::Upload creates, "apreq??????", in the /tmp directory was getting
unlink'd but there was still an open filehandle to it. This meant that the
space the image was taking up on the /tmp dir was not being cleared, but the
file wasn't showing up in the directory. And each image upload after this
was creating more stale filehandles and keeping more and more drive space
occupied. If Apache was restarted the filehandles were closed and the
memory was free'd. I assume when a child dies it also clears the memory,
but I'm not sure on that one.
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.
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.
-Jeff Hartmann