summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2017-05-09 08:33:37 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2017-05-09 08:33:37 +0200
commit7d1dde01baad1e387a93833498f45167ff504acd (patch)
treebefab853668b38a46b0c7a4cce3dca4e52d08026
parent79b57feab6babc566fca72a7ae8a889d7758651a (diff)
downloadvdr-7d1dde01baad1e387a93833498f45167ff504acd.tar.gz
vdr-7d1dde01baad1e387a93833498f45167ff504acd.tar.bz2
The constructor of cHash (via cHashBase) now has an additional parameter (OwnObjects); fixed a memory leak in cSectionSyncerHash
-rw-r--r--HISTORY8
-rw-r--r--eit.h7
-rw-r--r--tools.c12
-rw-r--r--tools.h11
4 files changed, 30 insertions, 8 deletions
diff --git a/HISTORY b/HISTORY
index fba29f56..9523a98e 100644
--- a/HISTORY
+++ b/HISTORY
@@ -8991,7 +8991,7 @@ Video Disk Recorder Revision History
current channel is listed.
- Fixed a possible crash when pulling the CAM while decrypting a channel with MTD.
-2017-05-03: Version 2.3.5
+2017-05-09: Version 2.3.5
- CAMs are now sent a generated EIT packet that contains a single 'present event' for
the current SID, in order to avoid any parental rating dialogs.
@@ -9001,3 +9001,9 @@ Video Disk Recorder Revision History
Dietmar Spingler).
- Events in the EIT that end before the EPG linger time are now ignored in the incoming
data stream, because they would just be deleted in the next schedules cleanup anyway.
+- The constructor of cHash (via cHashBase) now has an additional parameter (OwnObjects)
+ which, if set to true, makes the hash take ownership of the hashed objects, so that
+ they are deleted when the hash is cleared or destroyed.
+- Fixed a memory leak in cSectionSyncerHash. The cSectionSyncerEntry objects put into
+ the hash were never explicitly deleted. Now the cSectionSyncerHash takes ownership of
+ these objects.
diff --git a/eit.h b/eit.h
index 51af6433..c93aabc3 100644
--- a/eit.h
+++ b/eit.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: eit.h 4.1 2015/07/25 11:03:53 kls Exp $
+ * $Id: eit.h 4.2 2017/05/08 21:10:29 kls Exp $
*/
#ifndef __EIT_H
@@ -15,7 +15,10 @@
class cSectionSyncerEntry : public cListObject, public cSectionSyncer {};
-class cSectionSyncerHash : public cHash<cSectionSyncerEntry> {};
+class cSectionSyncerHash : public cHash<cSectionSyncerEntry> {
+public:
+ cSectionSyncerHash(void) : cHash(HASHSIZE, true) {};
+ };
class cEitFilter : public cFilter {
private:
diff --git a/tools.c b/tools.c
index 754673db..a8e6af1e 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 4.5 2016/12/23 14:03:40 kls Exp $
+ * $Id: tools.c 4.6 2017/05/09 08:32:54 kls Exp $
*/
#include "tools.h"
@@ -2312,9 +2312,10 @@ void cDynamicBuffer::Append(const uchar *Data, int Length)
// --- cHashBase -------------------------------------------------------------
-cHashBase::cHashBase(int Size)
+cHashBase::cHashBase(int Size, bool OwnObjects)
{
size = Size;
+ ownObjects = OwnObjects;
hashTable = (cList<cHashObject>**)calloc(size, sizeof(cList<cHashObject>*));
}
@@ -2348,6 +2349,13 @@ void cHashBase::Del(cListObject *Object, unsigned int Id)
void cHashBase::Clear(void)
{
for (int i = 0; i < size; i++) {
+ if (ownObjects) {
+ cList<cHashObject> *list = hashTable[i];
+ if (list) {
+ for (cHashObject *hob = list->First(); hob; hob = list->Next(hob))
+ delete hob->object;
+ }
+ }
delete hashTable[i];
hashTable[i] = NULL;
}
diff --git a/tools.h b/tools.h
index d2234c39..7941da5d 100644
--- a/tools.h
+++ b/tools.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 4.6 2017/03/16 16:04:43 kls Exp $
+ * $Id: tools.h 4.7 2017/05/09 08:33:37 kls Exp $
*/
#ifndef __TOOLS_H
@@ -825,9 +825,14 @@ class cHashBase {
private:
cList<cHashObject> **hashTable;
int size;
+ bool ownObjects;
unsigned int hashfn(unsigned int Id) const { return Id % size; }
protected:
- cHashBase(int Size);
+ cHashBase(int Size, bool OwnObjects);
+ ///< Creates a new hash of the given Size. If OwnObjects is true, the
+ ///< hash takes ownership of the objects given in the calls to Add(),
+ ///< and deletes them when Clear() is called or the hash is destroyed
+ ///< (unless the object has been removed from the hash by calling Del()).
public:
virtual ~cHashBase();
void Add(cListObject *Object, unsigned int Id);
@@ -841,7 +846,7 @@ public:
template<class T> class cHash : public cHashBase {
public:
- cHash(int Size = HASHSIZE) : cHashBase(Size) {}
+ cHash(int Size = HASHSIZE, bool OwnObjects = false) : cHashBase(Size, OwnObjects) {}
T *Get(unsigned int Id) const { return (T *)cHashBase::Get(Id); }
};