Skip Menu |
 

This queue is for tickets about the Audio-Wav CPAN distribution.

Report information
The Basics
Id: 71462
Status: resolved
Priority: 0/
Queue: Audio-Wav

People
Owner: Nobody in particular
Requestors: murali.ramanathan [...] gmail.com
Cc:
AdminCc:

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



Subject: Audio::Wav::Read
Download (untitled) / with headers
text/plain 1.5k
When the Audio::Wav::Read->read is called with a non-existent or invalid file, it correctly reports the problem. However, when the object goes out of scope, the following error comes up: (in cleanup) Can't call method "close" on an undefined value at /Library/Perl/5.8.8/Audio/Wav/Read.pm line 92. Now, looking @ the context for Line 92, I see that it hapens in the destructor: sub DESTROY { my $self = shift; return unless $self; if ( exists $self -> {'handle'} ) { $self -> {'handle'} -> close(); #### this is line 92 } if ( exists $self -> {'tools'} ) { delete $self -> {'tools'}; } } I see that only an 'if (exists $self->{handle})' test is being made; but, in the Audio::Wav::new constructor the {handle} member is created regardless of whether the open of the file succeeds or not: sub new { my $class = shift; my $file = shift; my $tools = shift; $file =~ s#//#/#g; my $size = -s $file; my $handle = new FileHandle "<$file"; my $self = { 'real_size' => $size, 'file' => $file, 'handle' => $handle, 'tools' => $tools, }; bless $self, $class; ,,, So, anyway, an easy fix to the problem would be to augment the if (exists ...) test with an if (defined ...) test: if (exists $self->{handle} && defined $self->{handle} ) in the destructor; alternatively, the constructor can be modified to not create the {handle} member unless the creation of the file handle actually succeeds. regards, murali.
From: murali.ramanathan [...] gmail.com
Download (untitled) / with headers
text/plain 1.8k
Ooops, sorry, the first line of my ticket should read, When Audio::Wav->read is called with a non-existent or invalid file ... rather than When Audio::Wav::Read->read is called ... cheers, murali. On Wed Oct 05 03:58:00 2011, ramanmu wrote: Show quoted text
> When the Audio::Wav::Read->read is called with a non-existent or > invalid file, it correctly > reports the problem. However, when the object goes out of scope, the > following error comes > up: > > > (in cleanup) Can't call method "close" on an undefined value at > /Library/Perl/5.8.8/Audio/Wav/Read.pm line 92. > > > Now, looking @ the context for Line 92, I see that it hapens in the > destructor: > > sub DESTROY { > my $self = shift; > return unless $self; > if ( exists $self -> {'handle'} ) { > $self -> {'handle'} -> close(); #### this is line 92 > } > if ( exists $self -> {'tools'} ) { > delete $self -> {'tools'}; > } > } > > I see that only an 'if (exists $self->{handle})' test is being made; > but, in the Audio::Wav::new > constructor the {handle} member is created regardless of whether the > open of the file > succeeds or not: > > sub new { > my $class = shift; > my $file = shift; > my $tools = shift; > $file =~ s#//#/#g; > my $size = -s $file; > my $handle = new FileHandle "<$file"; > > my $self = { > 'real_size' => $size, > 'file' => $file, > 'handle' => $handle, > 'tools' => $tools, > }; > > bless $self, $class; > > ,,, > > > So, anyway, an easy fix to the problem would be to augment the if > (exists ...) test with an if > (defined ...) test: > > if (exists $self->{handle} && defined $self->{handle} ) > > in the destructor; alternatively, the constructor can be modified to > not create the {handle} > member unless the creation of the file handle actually succeeds. > > regards, > murali.
Download (untitled) / with headers
text/plain 1.7k
Thanks Murali. A fix has been applied in SVN and will be included in 0.13 release which is coming shortly. Cheers, Brian On Wed Oct 05 03:58:00 2011, ramanmu wrote: Show quoted text
> When the Audio::Wav::Read->read is called with a non-existent or > invalid file, it correctly > reports the problem. However, when the object goes out of scope, the > following error comes > up: > > > (in cleanup) Can't call method "close" on an undefined value at > /Library/Perl/5.8.8/Audio/Wav/Read.pm line 92. > > > Now, looking @ the context for Line 92, I see that it hapens in the > destructor: > > sub DESTROY { > my $self = shift; > return unless $self; > if ( exists $self -> {'handle'} ) { > $self -> {'handle'} -> close(); #### this is line 92 > } > if ( exists $self -> {'tools'} ) { > delete $self -> {'tools'}; > } > } > > I see that only an 'if (exists $self->{handle})' test is being made; > but, in the Audio::Wav::new > constructor the {handle} member is created regardless of whether the > open of the file > succeeds or not: > > sub new { > my $class = shift; > my $file = shift; > my $tools = shift; > $file =~ s#//#/#g; > my $size = -s $file; > my $handle = new FileHandle "<$file"; > > my $self = { > 'real_size' => $size, > 'file' => $file, > 'handle' => $handle, > 'tools' => $tools, > }; > > bless $self, $class; > > ,,, > > > So, anyway, an easy fix to the problem would be to augment the if > (exists ...) test with an if > (defined ...) test: > > if (exists $self->{handle} && defined $self->{handle} ) > > in the destructor; alternatively, the constructor can be modified to > not create the {handle} > member unless the creation of the file handle actually succeeds. > > regards, > murali.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.