From 6e12febf3df0898233c788415db9831c012629d7 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 16 Sep 2015 10:51:27 -0400 Subject: [PATCH] initialize privacy_bitmask and check it before deletep[] to prevent segfault --- src/zm_monitor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 4455917e6..b66446c55 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -331,7 +331,8 @@ Monitor::Monitor( n_zones( p_n_zones ), zones( p_zones ), timestamps( 0 ), - images( 0 ) + images( 0 ), + privacy_bitmask( NULL ) { strncpy( name, p_name, sizeof(name) ); @@ -692,11 +693,13 @@ void Monitor::AddZones( int p_n_zones, Zone *p_zones[] ) void Monitor::AddPrivacyBitmask( Zone *p_zones[] ) { - delete[] privacy_bitmask; + if ( privacy_bitmask ) + delete[] privacy_bitmask; privacy_bitmask = NULL; Image *privacy_image = NULL; for ( int i = 0; i < n_zones; i++ ) + { if ( p_zones[i]->IsPrivacy() ) { if ( !privacy_image ) @@ -707,6 +710,7 @@ void Monitor::AddPrivacyBitmask( Zone *p_zones[] ) privacy_image->Fill( 0xff, p_zones[i]->GetPolygon() ); privacy_image->Outline( 0xff, p_zones[i]->GetPolygon() ); } + } // end foreach zone if ( privacy_image ) privacy_bitmask = privacy_image->Buffer(); }