From 37a4c67ae6a2ebbb3fb0bb53afed66fd7835fbf5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Oct 2016 11:33:25 -0400 Subject: [PATCH] move jpeg context freeing to a Deinitialise function instead of ~Image. Turn down the logging --- src/zm_image.cpp | 51 +++++++++++++++++++++++------------------------- src/zm_image.h | 4 ++-- src/zma.cpp | 1 + src/zmc.cpp | 2 ++ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index e73b20bcc..e3147a998 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -152,11 +152,13 @@ Image::Image( const Image &p_image ) strncpy( text, p_image.text, sizeof(text) ); } -Image::~Image() -{ +Image::~Image() { DumpImgBuffer(); - if ( initialised ) - { +} + +/* Should be called as part of program shutdown to free everything */ +void Image::Deinitialise() { + if ( initialised ) { /* delete[] y_table; delete[] uv_table; @@ -166,30 +168,25 @@ Image::~Image() delete[] b_u_table; */ initialised = false; - } - if ( readjpg_dcinfo ) - { - jpeg_destroy_decompress( readjpg_dcinfo ); - delete readjpg_dcinfo; - readjpg_dcinfo = 0; - } - if ( decodejpg_dcinfo ) - { - jpeg_destroy_decompress( decodejpg_dcinfo ); - delete decodejpg_dcinfo; - decodejpg_dcinfo = 0; - } -#if 0 -+// This creates a memleak because it isn't de-allocating the structures and it's doing it on every Image construct/destruct. -+// We need to refactor this code big time. - - for ( unsigned int quality=0; quality <= 100; quality += 1 ) { - if ( writejpg_ccinfo[quality] ) { - delete writejpg_ccinfo[quality]; - writejpg_ccinfo[quality] = NULL; + if ( readjpg_dcinfo ) { + jpeg_destroy_decompress( readjpg_dcinfo ); + delete readjpg_dcinfo; + readjpg_dcinfo = 0; } - } // end foreach quality -#endif + if ( decodejpg_dcinfo ) + { + jpeg_destroy_decompress( decodejpg_dcinfo ); + 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 + } } void Image::Initialise() diff --git a/src/zm_image.h b/src/zm_image.h index b63157c03..2f00ffd84 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -150,8 +150,6 @@ protected: int holdbuffer; /* Hold the buffer instead of replacing it with new one */ char text[1024]; -protected: - static void Initialise(); public: Image(); @@ -159,6 +157,8 @@ public: Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer=0); Image( const Image &p_image ); ~Image(); + static void Initialise(); + static void Deinitialise(); inline unsigned int Width() const { return( width ); } inline unsigned int Height() const { return( height ); } diff --git a/src/zma.cpp b/src/zma.cpp index 03ffe1726..b9483d7c9 100644 --- a/src/zma.cpp +++ b/src/zma.cpp @@ -198,6 +198,7 @@ int main( int argc, char *argv[] ) { fprintf( stderr, "Can't find monitor with id of %d\n", id ); } + Image::Deinitialise(); logTerm(); zmDbClose(); return( 0 ); diff --git a/src/zmc.cpp b/src/zmc.cpp index 76b16e6d0..809a27ce4 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -358,6 +358,8 @@ int main( int argc, char *argv[] ) delete [] next_delays; delete [] last_capture_times; + Image::Deinitialise(); + logTerm(); zmDbClose();