ZoneMinder/ZoneMinder — pull request #607 by manupap1 (2014-11-29 14:08:59+00:00)
Title: Fix some memory leaks in zma

Valgrind report (test of zma binary):
```
==2460== Memcheck, a memory error detector
==2460== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==2460== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==2460== Command: /usr/bin/zma -m3
==2460==
==2460==
==2460== HEAP SUMMARY:
==2460== in use at exit: 3,215 bytes in 24 blocks
==2460== total heap usage: 2,439 allocs, 2,415 frees, 2,964,275 bytes allocated
==2460==
==2460== 48 bytes in 1 blocks are still reachable in loss record 1 of 11
==2460== at 0x6707180: operator new(unsigned long) (vg_replace_malloc.c:324)
==2460== by 0xDDB6F4B: ??? (in /usr/lib/x86_64-linux-gnu/libjack.so.0.1.0)
==2460== by 0x5AEC9F9: call_init.part.0 (dl-init.c:78)
==2460== by 0x5AECAE2: call_init (dl-init.c:36)
==2460== by 0x5AECAE2: _dl_init (dl-init.c:126)
==2460== by 0x5ADF1C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==2460== by 0x1: ???
==2460== by 0xFFF0007D2: ???
==2460== by 0xFFF0007DF: ???
==2460==
==2460== 48 bytes in 1 blocks are still reachable in loss record 2 of 11
==2460== at 0x6707180: operator new(unsigned long) (vg_replace_malloc.c:324)
==2460== by 0xDDB6F69: ??? (in /usr/lib/x86_64-linux-gnu/libjack.so.0.1.0)
==2460== by 0x5AEC9F9: call_init.part.0 (dl-init.c:78)
==2460== by 0x5AECAE2: call_init (dl-init.c:36)
==2460== by 0x5AECAE2: _dl_init (dl-init.c:126)
==2460== by 0x5ADF1C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==2460== by 0x1: ???
==2460== by 0xFFF0007D2: ???
==2460== by 0xFFF0007DF: ???
==2460==
==2460== 167 bytes in 14 blocks are definitely lost in loss record 3 of 11
==2460== at 0x6706C20: malloc (vg_replace_malloc.c:296)
==2460== by 0x40F131: zmLoadConfig() (in /usr/bin/zma)
==2460== by 0x4078AC: main (in /usr/bin/zma)
==2460==
==2460== 200 bytes in 1 blocks are still reachable in loss record 4 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x445FC9: Monitor::Analyse() (in /usr/bin/zma)
==2460== by 0x407A6F: main (in /usr/bin/zma)
==2460==
==2460== 200 bytes in 1 blocks are still reachable in loss record 5 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x446003: Monitor::Analyse() (in /usr/bin/zma)
==2460== by 0x407A6F: main (in /usr/bin/zma)
==2460==
==2460== 256 bytes in 1 blocks are still reachable in loss record 6 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x428315: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== 256 bytes in 1 blocks are still reachable in loss record 7 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x4283C1: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== 510 bytes in 1 blocks are still reachable in loss record 8 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x42846D: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== 510 bytes in 1 blocks are still reachable in loss record 9 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x42847E: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== 510 bytes in 1 blocks are still reachable in loss record 10 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x42848F: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== 510 bytes in 1 blocks are still reachable in loss record 11 of 11
==2460== at 0x67078A0: operator new[](unsigned long) (vg_replace_malloc.c:389)
==2460== by 0x4284A0: Image::Initialise() (in /usr/bin/zma)
==2460== by 0x427994: Image::Image(int, int, int, int, unsigned char*) (in /usr/bin/zma)
==2460== by 0x441EAF: Monitor::Monitor(int, char const*, int, bool, char const*, Camera*, int, unsigned int, char const*, char const*, Coord const&, int, int, int, int, int, int, int, int, int, int, int, int, int, int, bool, unsigned int, Monitor::Purpose, int, Zone**) (in /usr/bin/zma)
==2460== by 0x44E64F: Monitor::Load(int, bool, Monitor::Purpose) (in /usr/bin/zma)
==2460== by 0x40798B: main (in /usr/bin/zma)
==2460==
==2460== LEAK SUMMARY:
==2460== definitely lost: 167 bytes in 14 blocks
==2460== indirectly lost: 0 bytes in 0 blocks
==2460== possibly lost: 0 bytes in 0 blocks
==2460== still reachable: 3,048 bytes in 10 blocks
==2460== suppressed: 0 bytes in 0 blocks
==2460==
==2460== For counts of detected and suppressed errors, rerun with: -v
==2460== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
Valgrind report with this patch:
```
==32487== Memcheck, a memory error detector
==32487== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==32487== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==32487== Command: /usr/bin/zma -m3
==32487==-
==32487==-
==32487== HEAP SUMMARY:
==32487== in use at exit: 96 bytes in 2 blocks
==32487== total heap usage: 2,425 allocs, 2,423 frees, 2,964,127 bytes allocated
==32487==-
==32487== 48 bytes in 1 blocks are still reachable in loss record 1 of 2
==32487== at 0x6707180: operator new(unsigned long) (vg_replace_malloc.c:324)
==32487== by 0xDDB6F4B: ??? (in /usr/lib/x86_64-linux-gnu/libjack.so.0.1.0)
==32487== by 0x5AEC9F9: call_init.part.0 (dl-init.c:78)
==32487== by 0x5AECAE2: call_init (dl-init.c:36)
==32487== by 0x5AECAE2: _dl_init (dl-init.c:126)
==32487== by 0x5ADF1C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==32487== by 0x1: ???
==32487== by 0xFFF0007D2: ???
==32487== by 0xFFF0007DF: ???
==32487==-
==32487== 48 bytes in 1 blocks are still reachable in loss record 2 of 2
==32487== at 0x6707180: operator new(unsigned long) (vg_replace_malloc.c:324)
==32487== by 0xDDB6F69: ??? (in /usr/lib/x86_64-linux-gnu/libjack.so.0.1.0)
==32487== by 0x5AEC9F9: call_init.part.0 (dl-init.c:78)
==32487== by 0x5AECAE2: call_init (dl-init.c:36)
==32487== by 0x5AECAE2: _dl_init (dl-init.c:126)
==32487== by 0x5ADF1C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
==32487== by 0x1: ???
==32487== by 0xFFF0007D2: ???
==32487== by 0xFFF0007DF: ???
==32487==-
==32487== LEAK SUMMARY:
==32487== definitely lost: 0 bytes in 0 blocks
==32487== indirectly lost: 0 bytes in 0 blocks
==32487== possibly lost: 0 bytes in 0 blocks
==32487== still reachable: 96 bytes in 2 blocks
==32487== suppressed: 0 bytes in 0 blocks
==32487==-
==32487== For counts of detected and suppressed errors, rerun with: -v
==32487== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
```

I believe the remaining leak records are false positives resulting from using a shared library.