]> git.vomp.tv Git - vompclient.git/commitdiff
Fix several memory leaks
authorChris Tallon <chris@vomp.tv>
Tue, 17 Jan 2017 21:44:21 +0000 (21:44 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 17 Jan 2017 21:44:21 +0000 (21:44 +0000)
14 files changed:
audioomx.cc [changed mode: 0644->0755]
boxstack.cc [changed mode: 0644->0755]
boxstack.h [changed mode: 0644->0755]
command.cc [changed mode: 0644->0755]
i18n.cc [changed mode: 0644->0755]
log.cc [changed mode: 0644->0755]
main.cc [changed mode: 0644->0755]
osdopenvg.cc [changed mode: 0644->0755]
remote.cc [changed mode: 0644->0755]
remotelinux.cc [changed mode: 0644->0755]
udp.cc [changed mode: 0644->0755]
vconnect.cc [changed mode: 0644->0755]
videoomx.cc [changed mode: 0644->0755]
vinfo.cc [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 0199fb3..d0d8e24
@@ -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;
        }
 
 
old mode 100644 (file)
new mode 100755 (executable)
index 3187a5c..fe26a21
@@ -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.
 
old mode 100644 (file)
new mode 100755 (executable)
index e730dff..733d371
@@ -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();
old mode 100644 (file)
new mode 100755 (executable)
index 8ad5c76..2bd5f49
@@ -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 (file)
new mode 100755 (executable)
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 (file)
new mode 100755 (executable)
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 (file)
new mode 100755 (executable)
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;
 }
old mode 100644 (file)
new mode 100755 (executable)
index f034b14..f417674
@@ -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<char*>::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<char*>::iterator itty=fontnames_keys.begin();
          while (itty!=fontnames_keys.end()) {
                  free((void*)*itty);
-
                  itty++;
          }
     }
old mode 100644 (file)
new mode 100755 (executable)
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;
                }
 
        }
old mode 100644 (file)
new mode 100755 (executable)
index 8f693b9..f5ef7b8
@@ -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 (file)
new mode 100755 (executable)
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;
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 83321ce..bb16ffe
@@ -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;
old mode 100644 (file)
new mode 100755 (executable)
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);