]> git.vomp.tv Git - vompclient.git/commitdiff
Use localtime_r instead of localtime. Fixes lockup
authorChris Tallon <chris@vomp.tv>
Wed, 25 May 2016 13:54:59 +0000 (14:54 +0100)
committerChris Tallon <chris@vomp.tv>
Wed, 25 May 2016 13:54:59 +0000 (14:54 +0100)
15 files changed:
demuxer.cc [changed mode: 0755->0644]
log.cc
media.cc
vepg.cc
vepglistadvanced.cc
vepgsettimer.cc
vradiorec.cc
vrecordinglistadvanced.cc
vrecordinglistclassic.cc
vtimeredit.cc
vtimerlist.cc
vvideolivetv.cc
vvideomedia.cc
vvideorec.cc
vwelcome.cc

old mode 100755 (executable)
new mode 100644 (file)
diff --git a/log.cc b/log.cc
index 1d8c57545ce614061d206ae2560611254f294479..a532d5a62e2da0e5f36a4f23f711d80dad7cdaa4 100644 (file)
--- a/log.cc
+++ b/log.cc
@@ -107,16 +107,15 @@ int Log::log(const char *fromModule, int level,const char* message, ...)
 #ifndef _MSC_VER
   struct timeval tv;
   gettimeofday(&tv, NULL);
-  struct tm* tms = localtime(&tv.tv_sec);
+  struct tm tms;
+  localtime_r(&tv.tv_sec, &tms);
+  spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", &tms);
+  spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
 #else
   struct _timeb tb;
   _ftime(&tb);
   struct tm* tms = localtime(&tb.time);
-#endif
   spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tms);
-#ifndef _MSC_VER
-  spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec);
-#else
   spaceLeft -= SNPRINTF(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tb.millitm);
 #endif
 
index f37661494dcf9a3ea3bfbf3db4914c818b3ee437..3901049e33eef59df151ee9c88db5172951293bf 100644 (file)
--- a/media.cc
+++ b/media.cc
@@ -230,16 +230,15 @@ bool Media::hasDisplayName() const {
 
 char * Media::getTimeString(char * buffer) const {
   if (! buffer) buffer=new char[TIMEBUFLEN];
-  struct tm ltime;
   time_t tTime = (time_t)getTime();
-  struct tm *btime = localtime(&tTime);
-  memcpy(&ltime,btime, sizeof(struct tm));
-  btime=&ltime;
-  if (btime && tTime != 0) {
+  struct tm btime;
+  localtime_r(&tTime, &btime);
+
+  if (tTime != 0) {
 #ifndef _MSC_VER
-  strftime(buffer,TIMEBUFLEN, "%0g/%0m/%0d %0H:%0M ", btime);
+  strftime(buffer,TIMEBUFLEN, "%0g/%0m/%0d %0H:%0M ", &btime);
 #else
-  strftime(buffer,TIMEBUFLEN, "%Y/%m/%d %H:%M ", btime);
+  strftime(buffer,TIMEBUFLEN, "%Y/%m/%d %H:%M ", &btime);
   
 #endif
   }
diff --git a/vepg.cc b/vepg.cc
index 94624f6ca2fb528c0b61fc4e2c787e7e2c0a79c9..a5babd0d97764bc76d1991fcfda5b001bb130c00 100644 (file)
--- a/vepg.cc
+++ b/vepg.cc
@@ -215,24 +215,24 @@ VEpg* VEpg::getInstance()
 void VEpg::setInfo(Event* event)
 {
   time_t t;
-  struct tm* btime; // to hold programme start and end time
+  struct tm btime; // to hold programme start and end time
   char timeString[9]; // to hold programme start and end time
   int length = strlen(event->title); // calculate length of programme title string
   char* title = new char[length + 15]; // create string to hold start time, end time and programme title
   time_t eventtime = event->time;
-  btime = localtime((time_t*)&eventtime); //get programme start time
+  localtime_r((time_t*)&eventtime, &btime); //get programme start time
 #ifndef _MSC_VER
-  strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm -
+  strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
 #else
-  strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm -
+  strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
 #endif
   strcpy(title, timeString); // put it in our buffer
   t = event->time + event->duration; //get programme end time
-  btime = localtime(&t);
+  localtime_r(&t, &btime);
 #ifndef _MSC_VER
-  strftime(timeString, 7, "%0H:%0M ", btime); // and format it as hh:mm -
+  strftime(timeString, 7, "%0H:%0M ", &btime); // and format it as hh:mm -
 #else
-  strftime(timeString, 7, "%H:%M ", btime); // and format it as hh:mm -
+  strftime(timeString, 7, "%H:%M ", &btime); // and format it as hh:mm -
 #endif
   strcat(title, timeString); // put it in our buffer
 
@@ -540,24 +540,24 @@ void VEpg::drawgrid() // redraws grid and select programme
   
 
   t = ltime;
-  struct tm* tms;
-  tms = localtime(&t);
-  strftime(timeString, 19, "%a %d %b", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%a %d %b", &tms);
   int timey = chanListbox.getRootBoxOffsetY() - getFontHeight() - 3;
   int timex = 135;
   drawTextRJ(timeString, timex - 10, timey, DrawStyle::LIGHTTEXT); // print date
-  strftime(timeString, 19, "%H:%M", tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, timex, timey, DrawStyle::LIGHTTEXT); // print left time
 
   rectangle(155, timey + getFontHeight(), 2, 7, white);
   t = t + 3600;
-  tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, timex + 180, timey, DrawStyle::LIGHTTEXT); // print middle time
   rectangle(335, timey + getFontHeight(), 2, 7, white);
   t = t + 3600;
-  tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, timex + 360, timey, DrawStyle::LIGHTTEXT); // print right time
   rectangle(515, timey + getFontHeight(), 2, 7, white);
   // pointer to selTime
@@ -759,11 +759,11 @@ void VEpg::paintCell(Event* event, int yOffset, const DrawStyle& bg, const DrawS
 
 time_t VEpg::prevHour(time_t* t)
 {
-  struct tm* tms;
-  tms = localtime(t);
-  tms->tm_sec = 0;
-  tms->tm_min = 0;
-  return mktime(tms);
+  struct tm tms;
+  localtime_r(t, &tms);
+  tms.tm_sec = 0;
+  tms.tm_min = 0;
+  return mktime(&tms);
 }
 
 void VEpg::processMessage(Message* m)
index 0ac6b92b671e27af0ee58c912d83927154020caa..7a02a8dabc9e4598734beebdcbf2f99179187308 100644 (file)
@@ -454,7 +454,7 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop)
   char tempA[300]; // FIXME  this is guesswork!
   char tempB[300]; // FIXME
   char tempC[300]; // FIXME
-  struct tm* btime;
+  struct tm btime;
 
 
 
@@ -469,10 +469,10 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop)
                  time_t eventStartTime = (time_t)currentEvent->time;
                  time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
 
-                 btime = localtime(&eventStartTime);
-                 strftime(tempA, 299, "%d/%m/%y %H:%M ", btime);
-                 btime = localtime(&eventEndTime);
-                 strftime(tempB, 299, "- %H:%M ", btime);
+                 localtime_r(&eventStartTime, &btime);
+                 strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
+                 localtime_r(&eventEndTime, &btime);
+                 strftime(tempB, 299, "- %H:%M ", &btime);
                  //#endif
                  sprintf(tempC, "\t %s\n \t \t%s%s", currentEvent->title,tempA,tempB);
                  // New TVMedia stuff
@@ -511,7 +511,7 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop)
   char tempA[300]; // FIXME  this is guesswork!
   char tempB[300]; // FIXME
   char tempC[300]; // FIXME
-  struct tm* btime;
+  struct tm btime;
 
 
 
@@ -536,10 +536,10 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop)
                  time_t eventStartTime = (time_t)currentEvent->time;
                  time_t eventEndTime = (time_t)(currentEvent->time + currentEvent->duration);
 
-                 btime = localtime(&eventStartTime);
-                 strftime(tempA, 299, "%H:%M ", btime);
-                 btime = localtime(&eventEndTime);
-                 strftime(tempB, 299, "- %H:%M ", btime);
+                 localtime_r(&eventStartTime, &btime);
+                 strftime(tempA, 299, "%H:%M ", &btime);
+                 localtime_r(&eventEndTime, &btime);
+                 strftime(tempB, 299, "- %H:%M ", &btime);
                  //#endif
                  sprintf(tempC, "%s\n%s\t %s%s", currentEvent->title, chan->name,tempA,tempB);
 
@@ -610,11 +610,11 @@ void VEpgListAdvanced::draw(bool doIndexPop)
 
 
        char freeSpace[50];
-       struct tm* btime;
+       struct tm btime;
        time_t now;
        time(&now);
-       btime = localtime(&now);
-       strftime(freeSpace, 299, "%d/%m/%y", btime);
+       localtime_r(&now, &btime);
+       strftime(freeSpace, 299, "%d/%m/%y", &btime);
 
        drawTextRJ(freeSpace, getWidth(), 5, DrawStyle::LIGHTTEXT);
 
index 582ce681d684fc26b3441d4a205576a58be48a7c..3f7ad7b18f2341ff56ec26f5e80cc39c6e3a214b 100644 (file)
@@ -84,7 +84,7 @@ char* VEpgSetTimer::genTimerString()
   char* timerString = new char[1024];
 
   // Other
-  struct tm* btime;
+  struct tm btime;
   int flags;
   char dateString[20];
   char startMargin[10];
@@ -108,9 +108,9 @@ char* VEpgSetTimer::genTimerString()
   else strcpy(startMargin, "5");
 
   startTime = event->time - (atoi(startMargin) * 60);
-  btime = localtime(&startTime);
-  strftime(dateString, 19, "%Y-%m-%d", btime);
-  strftime(startString, 9, "%H%M", btime);
+  localtime_r(&startTime, &btime);
+  strftime(dateString, 19, "%Y-%m-%d", &btime);
+  strftime(startString, 9, "%H%M", &btime);
 
   char* endMarginConfig = vdr->configLoad("Timers", "End margin");
   if (endMarginConfig)
@@ -121,8 +121,8 @@ char* VEpgSetTimer::genTimerString()
   else strcpy(endMargin, "5");
 
   endTime = event->time + event->duration + (atoi(endMargin) * 60);
-  btime = localtime(&endTime);
-  strftime(endString, 9, "%H%M", btime);
+  localtime_r(&endTime, &btime);
+  strftime(endString, 9, "%H%M", &btime);
 
   char* priorityConfig = vdr->configLoad("Timers", "Priority");
   if (priorityConfig)
@@ -178,22 +178,22 @@ void VEpgSetTimer::draw()
 
   char fullString[20];
   time_t t;
-  struct tm* btime;
+  struct tm btime;
   char timeString[10];
   time_t eventtime = event->time;
-  btime = localtime(&eventtime);
+  localtime_r(&eventtime, &btime);
 #ifndef _MSC_VER
-  strftime(timeString, 9, "%0H:%0M - ", btime); // and format it as hh:mm -
+  strftime(timeString, 9, "%0H:%0M - ", &btime); // and format it as hh:mm -
 #else
-   strftime(timeString, 9, "%H:%M - ", btime); // and format it as hh:mm -
+   strftime(timeString, 9, "%H:%M - ", &btime); // and format it as hh:mm -
 #endif
   strcpy(fullString, timeString); // put it in our buffer
   t = event->time + event->duration; //get programme end time
-  btime = localtime(&t);
+  localtime_r(&t, &btime);
 #ifndef _MSC_VER
-  strftime(timeString, 9, "%0H:%0M", btime); // and format it as hh:mm -
+  strftime(timeString, 9, "%0H:%0M", &btime); // and format it as hh:mm -
 #else
-   strftime(timeString, 9, "%H:%M", btime); // and format it as hh:mm -
+   strftime(timeString, 9, "%H:%M", &btime); // and format it as hh:mm -
 #endif
 
   strcat(fullString, timeString); // put it in our buffer
index 04f2cc3e03ae8c5d45cfa09d9ea76c67761acc8e..b48eec1074ca0ea5ebf870f4c3df5912991a7314 100644 (file)
@@ -429,8 +429,9 @@ void VRadioRec::drawBarClocks()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
 
   // Draw clocks
index b4fbb9c9d70d0543972f58394ec70e8b61861355..bed9504ab91d5d184a0e8d61a3c36753d330c475 100644 (file)
@@ -96,7 +96,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop)
 
   char tempA[300]; // FIXME  this is guesswork!
   char tempB[300]; // FIXME
-  struct tm* btime;
+  struct tm btime;
 
   Directory* currentSubDir;
   DirectoryList::iterator i;
@@ -127,12 +127,12 @@ void VRecordingListAdvanced::drawData(bool doIndexPop)
   {
     currentRec = *j;
     time_t recStartTime = (time_t)currentRec->getStartTime();
-    btime = localtime(&recStartTime);
+    localtime_r(&recStartTime, &btime);
 //NMT does not like this too!
        //#ifndef _MSC_VER
-//    strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
+//    strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime);
 //#else
-    strftime(tempA, 299, "%d/%m/%y %H:%M ", btime);
+    strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
 //#endif
     sprintf(tempB, "%c\t%s\n \t%s",  (currentRec->getNew() ? '*': ' '), currentRec->getProgName(),tempA);
     // New TVMedia stuff
@@ -281,14 +281,14 @@ void VRecordingListAdvanced::updateSelection()
                        RecordingList::iterator j;
                        RecordingList & recList = toShowDir->recList;
                        char tempA[300];
-                       struct tm* btime;
+                       struct tm btime;
                        for (j = recList.begin(); j != recList.end(); j++)
                        {
                                currentRec = *j;
 
                                time_t recStartTime = (time_t)currentRec->getStartTime();
-                               btime = localtime(&recStartTime);
-                               strftime(tempA, 299, "%d/%m/%y %H:%M ", btime);
+                               localtime_r(&recStartTime, &btime);
+                               strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime);
 
                                description<< tempA <<" "<< std::string(currentRec->getProgName()) << "\n";
 
index 1322e537fea6615c4c81c66e05ad44a84152b44f..82ffbb4967781ee8b9915763785c9593598baccb 100644 (file)
@@ -76,7 +76,7 @@ void VRecordingListClassic::drawData(bool doIndexPop)
 
   char tempA[300]; // FIXME  this is guesswork!
   char tempB[300]; // FIXME
-  struct tm* btime;
+  struct tm btime;
 
   Directory* currentSubDir;
   DirectoryList::iterator i;
@@ -97,12 +97,12 @@ void VRecordingListClassic::drawData(bool doIndexPop)
   {
     currentRec = *j;
     time_t recStartTime = (time_t)currentRec->getStartTime();
-    btime = localtime(&recStartTime);
+    localtime_r(&recStartTime, &btime);
 //NMT does not like this too!
        //#ifndef _MSC_VER
-//    strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
+//    strftime(tempA, 299, "%0d/%0m %0H:%0M ", &btime);
 //#else
-    strftime(tempA, 299, "%d/%m %H:%M ", btime);
+    strftime(tempA, 299, "%d/%m %H:%M ", &btime);
 //#endif
     sprintf(tempB, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName());
       
index 313f8ccdcbed592c09d25498ffa0685fc593db26..0e8795d5db8877e70415243a9bb45599bb1b01d7 100644 (file)
@@ -95,7 +95,7 @@ void VTimerEdit::draw()
 
   // Temp
   char buffer[1000];
-  struct tm* tms;
+  struct tm tms;
   xpos = 150;
   ypos = 50;
 
@@ -120,14 +120,14 @@ void VTimerEdit::draw()
 
   // Start
   time_t rectime = recTimer->startTime;
-  tms = localtime((time_t*)&rectime);
-  strftime(buffer, 999, "%d/%m %H:%M", tms);
+  localtime_r((time_t*)&rectime, &tms);
+  strftime(buffer, 999, "%d/%m %H:%M", &tms);
   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
 
   // Stop
   rectime = recTimer->startTime;
-  tms = localtime((time_t*)&rectime);
-  strftime(buffer, 999, "%d/%m %H:%M", tms);
+  localtime_r((time_t*)&rectime, &tms);
+  strftime(buffer, 999, "%d/%m %H:%M", &tms);
   drawText(buffer, xpos, ypos, DrawStyle::LIGHTTEXT);         ypos += fontheight;
 
   // Priority
index 2ecaf3f6c529da201d5c46b607426e76d1ec4c53..29d5027e83e5fc068c264b471d84e2c2cc99ff92 100644 (file)
@@ -137,7 +137,7 @@ bool VTimerList::load()
   char strA[300];
   char strB[300];
 
-  struct tm* btime;
+  struct tm btime;
 
   // FIXME all drawing stuff in this class and sl.clear somewhere?!
 
@@ -150,9 +150,9 @@ bool VTimerList::load()
   for (UINT i = 0; i < recTimerList->size(); i++)
   {
     recTimer = (*recTimerList)[i];
-       time_t rectime = recTimer->startTime;
-    btime = localtime((time_t*)&rectime);
-    strftime(strA, 299, "%d/%m %H:%M ", btime);
+    time_t rectime = recTimer->startTime;
+    localtime_r((time_t*)&rectime, &btime);
+    strftime(strA, 299, "%d/%m %H:%M ", &btime);
     SNPRINTF(strB, 299, "%s\t%s", strA, recTimer->getName());
     sl.addOption(strB, (ULONG)recTimer, first);
     first = 0;
@@ -171,8 +171,9 @@ void VTimerList::drawClock()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%d/%m %H:%M:%S", &tms);
   drawTextRJ(timeString, 560, 5, DrawStyle::LIGHTTEXT);
 
   Timers::getInstance()->setTimerT(this, 1, t + 1);
index d140d24b4e5b8db380d8d1ccc3ed686c4b3df729..0901d0d15695f03fad241bd27035b3431a6fc9f5 100644 (file)
@@ -770,7 +770,7 @@ void VVideoLiveTV::setNowNextData()
 
     char tempString[300];
     char tempString2[300];
-    struct tm* btime;
+    struct tm btime;
     Event* event;
     int eventListSize = eventList->size();
     std::stringstream string;
@@ -779,11 +779,11 @@ void VVideoLiveTV::setNowNextData()
       event = (*eventList)[i];
 
       time_t etime = event->time;
-      btime = localtime(&etime);
+      localtime_r(&etime, &btime);
 #ifndef _MSC_VER
-      strftime(tempString2, 299, "%0H:%0M ", btime);
+      strftime(tempString2, 299, "%0H:%0M ", &btime);
 #else
-      strftime(tempString2, 299, "%H:%M ", btime);
+      strftime(tempString2, 299, "%H:%M ", &btime);
 #endif
       SNPRINTF(tempString, 299, "%s %s", tempString2, event->title);
       string << tempString << "\n";
@@ -860,8 +860,9 @@ void VVideoLiveTV::setClock()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   clock.setText(timeString);
 
   time_t dt = 60 - (t % 60);  // seconds to the next minute
index 6f97b59ee81fcd51e5c9cfd804359df78a310f8a..02a14858c5dd5dc468486b2c62281a54300b845c 100644 (file)
@@ -615,8 +615,9 @@ void VVideoMedia::drawBarClocks()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
 
   ULLONG lenPTS=player->getLenPTS();
index 8fca5896c0687cfa2457cd044703784b7da1818a..715605386d988bb11b1de12f88894d7c21d80063 100644 (file)
@@ -963,8 +963,9 @@ void VVideoRec::drawBarClocks()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawText(timeString, barRegion.x + 624, barRegion.y + 12, DrawStyle::LIGHTTEXT);
 
   // Draw clocks
index 733a47dad9232ce192c29759fe6a8c5ece262355..b92ad5d6a2f062f9cb08b81999d8f2200458d47c 100644 (file)
@@ -160,8 +160,9 @@ void VWelcome::drawClock()
   char timeString[20];
   time_t t;
   time(&t);
-  struct tm* tms = localtime(&t);
-  strftime(timeString, 19, "%H:%M", tms);
+  struct tm tms;
+  localtime_r(&t, &tms);
+  strftime(timeString, 19, "%H:%M", &tms);
   drawTextRJ(timeString, 450, 5, DrawStyle::LIGHTTEXT);
 
   time_t dt = 60 - (t % 60);  // seconds to the next minute