From d185f05006d7be849902f169e4e3bc16662c7e37 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 3 Jan 2014 12:55:30 -0500 Subject: [PATCH] robustness/code style changes --- scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm | 12 +++++++++--- scripts/zmtrigger.pl.in | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm b/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm index 7c472591d..6af97122c 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Memory/Mapped.pm @@ -76,8 +76,11 @@ sub zmMemKey( $ ) sub zmMemAttach( $$ ) { - my $monitor = shift; - my $size = shift; + my ( $monitor, $size ) = @_; + if ( ! $size ) { + Error( "No size passed to zmMemAttach for monitor $$monitor{Id}\n" ); + return( undef ); + } if ( !defined($monitor->{MMapAddr}) ) { my $mmap_file = $Config{ZM_PATH_MAP}."/zm.mmap.".$monitor->{Id}; @@ -95,6 +98,7 @@ sub zmMemAttach( $$ ) if ( !$mmap_addr || !$mmap ) { Error( sprintf( "Can't mmap to file '%s': $!\n", $mmap_file ) ); + close( MMAP ); return( undef ); } $monitor->{MMapHandle} = \*MMAP; @@ -110,7 +114,9 @@ sub zmMemDetach( $ ) if ( $monitor->{MMap} ) { - munmap( ${$monitor->{MMap}} ); + if ( ! munmap( ${$monitor->{MMap}} ) ) { + Warn( "Unable to munmap for monitor $$monitor{Id}\n"); + } delete $monitor->{MMap}; } if ( $monitor->{MMapAddr} ) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 1b1477e67..d8929fab3 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -437,4 +437,7 @@ sub handleMessage { Error( "Unrecognised action '$action' in message '$message'\n" ); } -} +} # end sub handleMessage + +1; +__END__