From 3de4811a424e984a1dfa271a3be5f4137c935bc1 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 31 May 2009 10:02:20 +0200 Subject: [PATCH] Fixed a memory leak when reaching the end of a recording during replay --- CONTRIBUTORS | 1 + HISTORY | 2 ++ dvbplayer.c | 22 ++++++++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a6055064..eb6dfc90 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1217,6 +1217,7 @@ Reinhard Nissl cDvbPlayer::Action() for reporting a typo in aspect ratio 2.21:1 for reporting a problem in case the PIDs change during recording + for reporting a memory leak when reaching the end of a recording during replay Richard Robson for reporting freezing replay if a timer starts while in Transfer Mode from the diff --git a/HISTORY b/HISTORY index 81127e1d..234d625f 100644 --- a/HISTORY +++ b/HISTORY @@ -6112,3 +6112,5 @@ Video Disk Recorder Revision History - Fixed generating PAT/PMT version numbers in case the PIDs change during recording (reported by Reinhard Nissl). - Updated the Ukrainian OSD texts (thanks to Yarema Aka Knedlyk). +- Fixed a memory leak when reaching the end of a recording during replay (reported + by Reinhard Nissl). diff --git a/dvbplayer.c b/dvbplayer.c index 219de497..ebd9eac6 100644 --- a/dvbplayer.c +++ b/dvbplayer.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: dvbplayer.c 2.15 2009/04/19 15:19:10 kls Exp $ + * $Id: dvbplayer.c 2.16 2009/05/31 09:59:43 kls Exp $ */ #include "dvbplayer.h" @@ -461,9 +461,11 @@ void cDvbPlayer::Action(void) esyslog("ERROR: frame larger than buffer (%d > %d)", Length, MAXFRAMESIZE); Length = MAXFRAMESIZE; } - b = MALLOC(uchar, Length); + b = NULL; } - if (!eof) { + if (!eof && Length > 0) { + if (!b) + b = MALLOC(uchar, Length); int r = nonBlockingFileReader->Read(replayFile, b, Length); if (r > 0) { WaitingForData = false; @@ -475,13 +477,17 @@ void cDvbPlayer::Action(void) readFrame = new cFrame(b, -r, ftUnknown, readIndex, Pts); // hands over b to the ringBuffer b = NULL; } - else if (r == 0) - eof = true; else if (r < 0 && errno == EAGAIN) WaitingForData = true; - else if (r < 0 && FATALERRNO) { - LOG_ERROR; - break; + else { + free(b); + b = NULL; + if (r == 0) + eof = true; + else if (r < 0 && FATALERRNO) { + LOG_ERROR; + break; + } } } }