Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the File-MimeInfo CPAN distribution.

Report information
The Basics
Id: 93221
Status: resolved
Priority: 0/
Queue: File-MimeInfo

People
Owner: Nobody in particular
Requestors: chrissicool [...] googlemail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Double-close on a filehandle
Date: Fri, 21 Feb 2014 11:30:57 +0100
To: bug-File-MimeInfo [...] rt.cpan.org
From: Christian Ludwig <chrissicool [...] googlemail.com>
I ran into the following error: Can't use an undefined value as a symbol reference at /usr/share/perl5/File/MimeInfo/Magic.pm line 46. The problem is that _magic() closes the fd when it finds a result for lower priority rules. mimetype() then tries to close it again. Since we take a completely different route in mimetype() if 'ref file' is true, we can close the fd safely whenever the low-priority rules return one. The appended patch fixes the issue.

Message body is not shown because sender requested not to inline it.

On Fri Feb 21 05:31:16 2014, chrissicool@googlemail.com wrote: Show quoted text
> I ran into the following error: > > Can't use an undefined value as a symbol reference at > /usr/share/perl5/File/MimeInfo/Magic.pm line 46. > > The problem is that _magic() closes the fd when it finds a result for > lower priority rules. mimetype() then tries to close it again. > > Since we take a completely different route in mimetype() if 'ref file' > is true, we can close the fd safely whenever the low-priority rules > return one.
Hi Chris, Thanks for your bug report. Would you be able to supply a test case? I'm thinking it might be better to not close the file handle we're returning in _magic() on line 78, do you agree? https://github.com/mbeijen/File-MimeInfo/blob/master/lib/File/MimeInfo/Magic.pm#L78 -- Mike
Subject: Re: [rt.cpan.org #93221] Double-close on a filehandle
Date: Wed, 26 Feb 2014 22:59:36 +0100
To: bug-File-MimeInfo [...] rt.cpan.org
From: Christian Ludwig <chrissicool [...] googlemail.com>
Hi, On So, 2014-02-23 at 15:50 -0500, Michiel Beijen via RT wrote: Show quoted text
> Thanks for your bug report. Would you be able to supply a test case?
In my setup, I see that error only for files of type application/octet-stream. Then I saw that there is no test for the default file types. Please find my tests on GitHub at [1]. Confusingly enough the tests all pass. Granted, my setup is a little more complicated. I am running threaded Perl using async workers. That triggers the problem "every now and then". Show quoted text
> I'm thinking it might be better to not close the file handle we're returning in _magic() on line 78, do you agree? > https://github.com/mbeijen/File-MimeInfo/blob/master/lib/File/MimeInfo/Magic.pm#L78
In my opinion it should better be the other way around. Why not close the file in _magic() again? And if you don't ant to re-open the same file multiple times, perhaps make _magic() only handle fd refs. I think it's easier to read when calls to open() and close() are in the same function. [1] https://github.com/chrissicool/File-MimeInfo/commit/ff684d3f27f16b81dd17355d5ef582b082465d12 - Christian
Thanks for your reporting and fixing this issue! I've included your patch & fix and released 0.22 to CPAN. -- Mike