Merge pull request #1646 from connortechnology/fix_zm_image_memleak

move jpeg context freeing to a Deinitialise function instead of ~Image
This commit is contained in:
Steve Gilvarry 2016-10-20 05:33:01 +11:00 committed by GitHub
commit b723e08b17
4 changed files with 39 additions and 30 deletions

View File

@ -152,11 +152,13 @@ Image::Image( const Image &p_image )
strncpy( text, p_image.text, sizeof(text) ); strncpy( text, p_image.text, sizeof(text) );
} }
Image::~Image() Image::~Image() {
{
DumpImgBuffer(); DumpImgBuffer();
if ( initialised ) }
{
/* Should be called as part of program shutdown to free everything */
void Image::Deinitialise() {
if ( initialised ) {
/* /*
delete[] y_table; delete[] y_table;
delete[] uv_table; delete[] uv_table;
@ -166,18 +168,24 @@ Image::~Image()
delete[] b_u_table; delete[] b_u_table;
*/ */
initialised = false; initialised = false;
} if ( readjpg_dcinfo ) {
if ( readjpg_dcinfo ) jpeg_destroy_decompress( readjpg_dcinfo );
{ delete readjpg_dcinfo;
jpeg_destroy_decompress( readjpg_dcinfo ); readjpg_dcinfo = 0;
delete readjpg_dcinfo; }
readjpg_dcinfo = 0; if ( decodejpg_dcinfo )
} {
if ( decodejpg_dcinfo ) jpeg_destroy_decompress( decodejpg_dcinfo );
{ delete decodejpg_dcinfo;
jpeg_destroy_decompress( decodejpg_dcinfo ); decodejpg_dcinfo = 0;
delete decodejpg_dcinfo; }
decodejpg_dcinfo = 0; for ( unsigned int quality=0; quality <= 100; quality += 1 ) {
if ( writejpg_ccinfo[quality] ) {
jpeg_destroy_compress( writejpg_ccinfo[quality] );
delete writejpg_ccinfo[quality];
writejpg_ccinfo[quality] = NULL;
}
} // end foreach quality
} }
} }
@ -187,14 +195,14 @@ void Image::Initialise()
if(config.fast_image_blends) { if(config.fast_image_blends) {
if(config.cpu_extensions && sseversion >= 20) { if(config.cpu_extensions && sseversion >= 20) {
fptr_blend = &sse2_fastblend; /* SSE2 fast blend */ fptr_blend = &sse2_fastblend; /* SSE2 fast blend */
Debug(2,"Blend: Using SSE2 fast blend function"); Debug(4,"Blend: Using SSE2 fast blend function");
} else { } else {
fptr_blend = &std_fastblend; /* standard fast blend */ fptr_blend = &std_fastblend; /* standard fast blend */
Debug(2,"Blend: Using fast blend function"); Debug(4,"Blend: Using fast blend function");
} }
} else { } else {
fptr_blend = &std_blend; fptr_blend = &std_blend;
Debug(2,"Blend: Using standard blend function"); Debug(4,"Blend: Using standard blend function");
} }
__attribute__((aligned(16))) uint8_t blend1[16] = {142,255,159,91,88,227,0,52,37,80,152,97,104,252,90,82}; __attribute__((aligned(16))) uint8_t blend1[16] = {142,255,159,91,88,227,0,52,37,80,152,97,104,252,90,82};
@ -223,7 +231,7 @@ void Image::Initialise()
fptr_delta8_argb = &ssse3_delta8_argb; fptr_delta8_argb = &ssse3_delta8_argb;
fptr_delta8_abgr = &ssse3_delta8_abgr; fptr_delta8_abgr = &ssse3_delta8_abgr;
fptr_delta8_gray8 = &sse2_delta8_gray8; fptr_delta8_gray8 = &sse2_delta8_gray8;
Debug(2,"Delta: Using SSSE3 delta functions"); Debug(4,"Delta: Using SSSE3 delta functions");
} else if(sseversion >= 20) { } else if(sseversion >= 20) {
/* SSE2 available */ /* SSE2 available */
fptr_delta8_rgba = &sse2_delta8_rgba; fptr_delta8_rgba = &sse2_delta8_rgba;
@ -240,7 +248,7 @@ void Image::Initialise()
// fptr_delta8_argb = &std_delta8_argb; // fptr_delta8_argb = &std_delta8_argb;
// fptr_delta8_abgr = &std_delta8_abgr; // fptr_delta8_abgr = &std_delta8_abgr;
fptr_delta8_gray8 = &sse2_delta8_gray8; fptr_delta8_gray8 = &sse2_delta8_gray8;
Debug(2,"Delta: Using SSE2 delta functions"); Debug(4,"Delta: Using SSE2 delta functions");
} else { } else {
/* No suitable SSE version available */ /* No suitable SSE version available */
fptr_delta8_rgba = &std_delta8_rgba; fptr_delta8_rgba = &std_delta8_rgba;
@ -248,7 +256,7 @@ void Image::Initialise()
fptr_delta8_argb = &std_delta8_argb; fptr_delta8_argb = &std_delta8_argb;
fptr_delta8_abgr = &std_delta8_abgr; fptr_delta8_abgr = &std_delta8_abgr;
fptr_delta8_gray8 = &std_delta8_gray8; fptr_delta8_gray8 = &std_delta8_gray8;
Debug(2,"Delta: Using standard delta functions"); Debug(4,"Delta: Using standard delta functions");
} }
} else { } else {
/* CPU extensions disabled */ /* CPU extensions disabled */
@ -257,7 +265,7 @@ void Image::Initialise()
fptr_delta8_argb = &std_delta8_argb; fptr_delta8_argb = &std_delta8_argb;
fptr_delta8_abgr = &std_delta8_abgr; fptr_delta8_abgr = &std_delta8_abgr;
fptr_delta8_gray8 = &std_delta8_gray8; fptr_delta8_gray8 = &std_delta8_gray8;
Debug(2,"Delta: CPU extensions disabled, using standard delta functions"); Debug(4,"Delta: CPU extensions disabled, using standard delta functions");
} }
/* Use SSSE3 deinterlace functions? */ /* Use SSSE3 deinterlace functions? */
@ -267,23 +275,23 @@ void Image::Initialise()
fptr_deinterlace_4field_argb = &ssse3_deinterlace_4field_argb; fptr_deinterlace_4field_argb = &ssse3_deinterlace_4field_argb;
fptr_deinterlace_4field_abgr = &ssse3_deinterlace_4field_abgr; fptr_deinterlace_4field_abgr = &ssse3_deinterlace_4field_abgr;
fptr_deinterlace_4field_gray8 = &ssse3_deinterlace_4field_gray8; fptr_deinterlace_4field_gray8 = &ssse3_deinterlace_4field_gray8;
Debug(2,"Deinterlace: Using SSSE3 delta functions"); Debug(4,"Deinterlace: Using SSSE3 delta functions");
} else { } else {
fptr_deinterlace_4field_rgba = &std_deinterlace_4field_rgba; fptr_deinterlace_4field_rgba = &std_deinterlace_4field_rgba;
fptr_deinterlace_4field_bgra = &std_deinterlace_4field_bgra; fptr_deinterlace_4field_bgra = &std_deinterlace_4field_bgra;
fptr_deinterlace_4field_argb = &std_deinterlace_4field_argb; fptr_deinterlace_4field_argb = &std_deinterlace_4field_argb;
fptr_deinterlace_4field_abgr = &std_deinterlace_4field_abgr; fptr_deinterlace_4field_abgr = &std_deinterlace_4field_abgr;
fptr_deinterlace_4field_gray8 = &std_deinterlace_4field_gray8; fptr_deinterlace_4field_gray8 = &std_deinterlace_4field_gray8;
Debug(2,"Deinterlace: Using standard delta functions"); Debug(4,"Deinterlace: Using standard delta functions");
} }
/* Use SSE2 aligned memory copy? */ /* Use SSE2 aligned memory copy? */
if(config.cpu_extensions && sseversion >= 20) { if(config.cpu_extensions && sseversion >= 20) {
fptr_imgbufcpy = &sse2_aligned_memcpy; fptr_imgbufcpy = &sse2_aligned_memcpy;
Debug(2,"Image buffer copy: Using SSE2 aligned memcpy"); Debug(4,"Image buffer copy: Using SSE2 aligned memcpy");
} else { } else {
fptr_imgbufcpy = &memcpy; fptr_imgbufcpy = &memcpy;
Debug(2,"Image buffer copy: Using standard memcpy"); Debug(4,"Image buffer copy: Using standard memcpy");
} }
/* Code below relocated from zm_local_camera */ /* Code below relocated from zm_local_camera */

View File

@ -137,7 +137,6 @@ protected:
static jpeg_decompress_struct *decodejpg_dcinfo; static jpeg_decompress_struct *decodejpg_dcinfo;
static struct zm_error_mgr jpg_err; static struct zm_error_mgr jpg_err;
protected:
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
unsigned int pixels; unsigned int pixels;
@ -150,8 +149,6 @@ protected:
int holdbuffer; /* Hold the buffer instead of replacing it with new one */ int holdbuffer; /* Hold the buffer instead of replacing it with new one */
char text[1024]; char text[1024];
protected:
static void Initialise();
public: public:
Image(); Image();
@ -159,6 +156,8 @@ public:
Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0); Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0);
Image( const Image &p_image ); Image( const Image &p_image );
~Image(); ~Image();
static void Initialise();
static void Deinitialise();
inline unsigned int Width() const { return( width ); } inline unsigned int Width() const { return( width ); }
inline unsigned int Height() const { return( height ); } inline unsigned int Height() const { return( height ); }

View File

@ -198,6 +198,7 @@ int main( int argc, char *argv[] )
{ {
fprintf( stderr, "Can't find monitor with id of %d\n", id ); fprintf( stderr, "Can't find monitor with id of %d\n", id );
} }
Image::Deinitialise();
logTerm(); logTerm();
zmDbClose(); zmDbClose();
return( 0 ); return( 0 );

View File

@ -357,6 +357,7 @@ int main( int argc, char *argv[] )
delete [] next_delays; delete [] next_delays;
delete [] last_capture_times; delete [] last_capture_times;
Image::Deinitialise();
logTerm(); logTerm();
zmDbClose(); zmDbClose();