Merge pull request #607 from manupap1/memory_fix_leaks

Fix some memory leaks in zma
This commit is contained in:
Isaac Connor 2014-11-29 10:18:17 -05:00
commit 02cdc37e3c
4 changed files with 38 additions and 15 deletions

View File

@ -29,7 +29,6 @@ void zmLoadConfig()
{
FILE *cfg;
char line[512];
char *val;
if ( (cfg = fopen( ZM_CONFIG, "r")) == NULL )
{
Fatal( "Can't open %s: %s", ZM_CONFIG, strerror(errno) );
@ -82,19 +81,16 @@ void zmLoadConfig()
white_len = strspn( val_ptr, " \t" );
val_ptr += white_len;
val = (char *)malloc( strlen(val_ptr)+1 );
strncpy( val, val_ptr, strlen(val_ptr)+1 );
if ( strcasecmp( name_ptr, "ZM_DB_HOST" ) == 0 )
staticConfig.DB_HOST = val;
staticConfig.DB_HOST = std::string(val_ptr);
else if ( strcasecmp( name_ptr, "ZM_DB_NAME" ) == 0 )
staticConfig.DB_NAME = val;
staticConfig.DB_NAME = std::string(val_ptr);
else if ( strcasecmp( name_ptr, "ZM_DB_USER" ) == 0 )
staticConfig.DB_USER = val;
staticConfig.DB_USER = std::string(val_ptr);
else if ( strcasecmp( name_ptr, "ZM_DB_PASS" ) == 0 )
staticConfig.DB_PASS = val;
staticConfig.DB_PASS = std::string(val_ptr);
else if ( strcasecmp( name_ptr, "ZM_PATH_WEB" ) == 0 )
staticConfig.PATH_WEB = val;
staticConfig.PATH_WEB = std::string(val_ptr);
else
{
// We ignore this now as there may be more parameters than the

View File

@ -140,6 +140,22 @@ Image::Image( const Image &p_image )
Image::~Image()
{
DumpImgBuffer();
if ( initialised )
{
delete[] y_table;
delete[] uv_table;
delete[] r_v_table;
delete[] g_v_table;
delete[] g_u_table;
delete[] b_u_table;
initialised = false;
}
if ( jpg_dcinfo )
{
jpeg_destroy_decompress( jpg_dcinfo );
delete jpg_dcinfo;
jpg_dcinfo = 0;
}
}
void Image::Initialise()

View File

@ -317,7 +317,9 @@ Monitor::Monitor(
last_motion_score(0),
camera( p_camera ),
n_zones( p_n_zones ),
zones( p_zones )
zones( p_zones ),
timestamps( 0 ),
images( 0 )
{
strncpy( name, p_name, sizeof(name) );
@ -567,6 +569,14 @@ bool Monitor::connect() {
Monitor::~Monitor()
{
if ( timestamps ) {
delete[] timestamps;
timestamps = 0;
}
if ( images ) {
delete[] images;
images = 0;
}
if ( mem_ptr ) {
if ( event )
Info( "%s: %03d - Closing event %d, shutting down", name, image_count, event->Id() );
@ -1234,8 +1244,6 @@ bool Monitor::Analyse()
}
static bool static_undef = true;
static struct timeval **timestamps;
static Image **images;
static int last_section_mod = 0;
static bool last_signal;

View File

@ -282,12 +282,15 @@ protected:
Event *event;
int n_zones;
int n_zones;
Zone **zones;
int iDoNativeMotDet;
struct timeval **timestamps;
Image **images;
int n_linked_monitors;
int iDoNativeMotDet;
int n_linked_monitors;
MonitorLink **linked_monitors;
public: