From 9eb1f53ab8d4f6721d5a76fb608fd28ee64999eb Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 17 Jan 2017 21:44:21 +0000 Subject: [PATCH] Fix several memory leaks --- audioomx.cc | 5 +++++ boxstack.cc | 13 ++++++++----- boxstack.h | 1 + command.cc | 15 +++++++++++---- i18n.cc | 1 + log.cc | 2 +- main.cc | 1 - osdopenvg.cc | 12 ++++++++++-- remote.cc | 1 + remotelinux.cc | 1 + udp.cc | 1 + vconnect.cc | 0 videoomx.cc | 1 + vinfo.cc | 2 ++ 14 files changed, 43 insertions(+), 13 deletions(-) mode change 100644 => 100755 audioomx.cc mode change 100644 => 100755 boxstack.cc mode change 100644 => 100755 boxstack.h mode change 100644 => 100755 command.cc mode change 100644 => 100755 i18n.cc mode change 100644 => 100755 log.cc mode change 100644 => 100755 main.cc mode change 100644 => 100755 osdopenvg.cc mode change 100644 => 100755 remote.cc mode change 100644 => 100755 remotelinux.cc mode change 100644 => 100755 udp.cc mode change 100644 => 100755 vconnect.cc mode change 100644 => 100755 videoomx.cc mode change 100644 => 100755 vinfo.cc diff --git a/audioomx.cc b/audioomx.cc old mode 100644 new mode 100755 index 0199fb3..d0d8e24 --- a/audioomx.cc +++ b/audioomx.cc @@ -193,6 +193,7 @@ bool AudioOMX::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "PCMMultichannel") == 0) { prefered_ac3 = 2; } + delete[] name; } name = vdr->configLoad("AudioOMX", "Mp2DecodingMode"); @@ -205,6 +206,7 @@ bool AudioOMX::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "PCMMultichannel") == 0) { prefered_mp2 = 2; } + delete[] name; } name = vdr->configLoad("AudioOMX", "AACDecodingMode"); @@ -217,6 +219,7 @@ bool AudioOMX::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "PCMMultichannel") == 0) { prefered_aac = 2; } + delete[] name; } name = vdr->configLoad("AudioOMX", "Mp3DecodingMode"); @@ -229,6 +232,7 @@ bool AudioOMX::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "PCMMultichannel") == 0) { prefered_mp3 = 2; } + delete[] name; } name = vdr->configLoad("AudioOMX", "AudioOutput"); @@ -239,6 +243,7 @@ bool AudioOMX::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "HDMI") == 0) { hdmi = true; } + delete[] name; } diff --git a/boxstack.cc b/boxstack.cc old mode 100644 new mode 100755 index 3187a5c..fe26a21 --- a/boxstack.cc +++ b/boxstack.cc @@ -55,14 +55,17 @@ int BoxStack::init() int BoxStack::shutdown() { if (!initted) return 0; - - // FIXME don't think this can work properly, removeAll leaves the wallpaper there! removeAll(); - initted = 0; return 1; } +void BoxStack::removeAll() +{ + removeAllExceptWallpaper(); + if (numBoxes == 1) remove(boxes[0]); +} + int BoxStack::addVideoDisplay(Boxx* box,VideoDisplay vd) { boxLock.Lock(); @@ -147,7 +150,7 @@ int BoxStack::remove(Boxx* toDelete) boxLock.Unlock(); -toDelete->preDelete(); + toDelete->preDelete(); boxLock.Lock(); @@ -447,7 +450,7 @@ void BoxStack::boxSplit(Region r, int start, int end, int direction, RegionList& // ---------------------------------------------------- END OF REMOVE CODE -void BoxStack::removeAll() +void BoxStack::removeAllExceptWallpaper() { // 1.. Don't delete wallpaper. No point. diff --git a/boxstack.h b/boxstack.h old mode 100644 new mode 100755 index e730dff..733d371 --- a/boxstack.h +++ b/boxstack.h @@ -56,6 +56,7 @@ class BoxStack // These functions do internal locking, so can be called directly from any thread. Hopefully. int add(Boxx*); int remove(Boxx*); + void removeAllExceptWallpaper(); void removeAll(); void update(Boxx*, Region* regionToUpdate = NULL); void redrawAllBoxes(); diff --git a/command.cc b/command.cc old mode 100644 new mode 100755 index 8ad5c76..2bd5f49 --- a/command.cc +++ b/command.cc @@ -267,6 +267,11 @@ void Command::run() #endif + + boxstack->removeAllExceptWallpaper(); + boxstack->remove(wallpaper); + delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; + } void Command::setSignal(int signalReceived) @@ -495,7 +500,7 @@ void Command::processMessage(Message* m) } case Message::CHANGE_LANGUAGE: { - boxstack->removeAll(); + boxstack->removeAllExceptWallpaper(); boxstack->update(wallpaper); I18n::initialize(); if (!VDR::getInstance()->isConnected()) { connectionLost(); break; } @@ -670,7 +675,7 @@ void Command::doPowerOff() if (!isStandby) { VDR::getInstance()->shutdownVDR(); - boxstack->removeAll(); + boxstack->removeAllExceptWallpaper(); Video::getInstance()->signalOff(); boxstack->update(wallpaper); @@ -720,7 +725,7 @@ void Command::doFromTheTop(bool which) { logger->unsetExternLogger(); VDR::getInstance()->disconnect(); - boxstack->removeAll(); + boxstack->removeAllExceptWallpaper(); boxstack->update(wallpaper); connLost = NULL; @@ -912,8 +917,10 @@ void Command::doJustConnected(VConnect* vconnect) // Oh sheesh, need to switch format. Bye bye TV... // Take everything down - boxstack->removeAll(); + boxstack->removeAllExceptWallpaper(); boxstack->remove(wallpaper); + delete wallpaper_pict; wallpaper_pict = NULL; wallpaper = NULL; + Osd* osd = Osd::getInstance(); #ifndef __ANDROID__ osd->shutdown(); diff --git a/i18n.cc b/i18n.cc old mode 100644 new mode 100755 index 091701b..cc2c6a0 --- a/i18n.cc +++ b/i18n.cc @@ -55,6 +55,7 @@ int I18n::initialize(void) vdr->configSave("General", "LangCode", code.c_str()); } vdr->getLanguageContent(code, Translations); + if (lang) delete[] lang; return 1; } diff --git a/log.cc b/log.cc old mode 100644 new mode 100755 index a532d5a..c67ea9d --- a/log.cc +++ b/log.cc @@ -90,7 +90,7 @@ int Log::init(int startLogLevel,const char* fileName, int tenabled) int Log::shutdown() { if (!initted) return 1; - if (enabled) fclose(logfile); + if (enabled && (logfile != stdout)) fclose(logfile); return 1; } diff --git a/main.cc b/main.cc old mode 100644 new mode 100755 index 46aa498..29b9fcb --- a/main.cc +++ b/main.cc @@ -398,7 +398,6 @@ int main(int argc, char** argv) command->run(); // When that returns quit ------------------------------------------------------------------------------------------ - shutdown(0); return 0; } diff --git a/osdopenvg.cc b/osdopenvg.cc old mode 100644 new mode 100755 index f034b14..f417674 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -88,6 +88,10 @@ OsdOpenVG::~OsdOpenVG() if (cur_fontname) free(cur_fontname); if (freetype_inited) FT_Done_Face(ft_face); + + // I think the following is broken as it is, but also possibly it shouldn't be free()ing the memory + // pointed at anyway, so it's correctly not working?! + if (!fontnames.size()) { vector::iterator itty=fontnames.begin(); while (itty!=fontnames.end()) { @@ -96,11 +100,15 @@ OsdOpenVG::~OsdOpenVG() itty++; } } - if (!fontnames_keys.size()) { + + // end + + + + if (fontnames_keys.size()) { vector::iterator itty=fontnames_keys.begin(); while (itty!=fontnames_keys.end()) { free((void*)*itty); - itty++; } } diff --git a/remote.cc b/remote.cc old mode 100644 new mode 100755 index d0bf896..2144520 --- a/remote.cc +++ b/remote.cc @@ -258,6 +258,7 @@ void Remote::LoadKeysConfig(VDR *vdr,const char *cfg) if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) { translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc; } + delete[] keytrans; } } diff --git a/remotelinux.cc b/remotelinux.cc old mode 100644 new mode 100755 index 8f693b9..f5ef7b8 --- a/remotelinux.cc +++ b/remotelinux.cc @@ -991,6 +991,7 @@ bool RemoteLinux::loadOptionsfromServer(VDR* vdr) } else if (STRCASECMP(name, "Cec") == 0) { cechandlesvolume=true; } + delete[] name; } return Remote::loadOptionsfromServer(vdr); } diff --git a/udp.cc b/udp.cc old mode 100644 new mode 100755 index f0d5e74..3486346 --- a/udp.cc +++ b/udp.cc @@ -44,6 +44,7 @@ int UDP::shutdown() if (!initted) return 1; if (threadIsActive()) threadCancel(); ds->shutdown(); + delete ds; initted = 0; return 1; diff --git a/vconnect.cc b/vconnect.cc old mode 100644 new mode 100755 diff --git a/videoomx.cc b/videoomx.cc old mode 100644 new mode 100755 index 83321ce..bb16ffe --- a/videoomx.cc +++ b/videoomx.cc @@ -248,6 +248,7 @@ bool VideoOMX::loadOptionsfromServer(VDR* vdr) deinterlace = 3; // this does not activate deinterlacing but a image filter, just for fun }*/ Log::getInstance()->log("Video", Log::DEBUG, "Set deinterlacing to %s %d",name,deinterlace); + delete[] name; } return true; diff --git a/vinfo.cc b/vinfo.cc old mode 100644 new mode 100755 index 202a6d1..2889548 --- a/vinfo.cc +++ b/vinfo.cc @@ -52,6 +52,7 @@ void VInfo::setDropThrough() void VInfo::setMainText(const char* takeText) { + if (mainText) delete[] mainText; int length = strlen(takeText); mainText = new char[length + 1]; strcpy(mainText, takeText); @@ -60,6 +61,7 @@ void VInfo::setMainText(const char* takeText) void VInfo::setOneLiner(const char* takeText) { + if (mainText) delete[] mainText; int length = strlen(takeText); mainText = new char[length + 1]; strcpy(mainText, takeText); -- 2.39.2