diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2011-02-25 15:25:42 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2011-02-25 15:25:42 +0100 |
commit | d1ab9dbc5f0c35aa10ee0c67b9dc2eb6fd31dd13 (patch) | |
tree | 01b6346cf321f0c2569b2c12f43d931e5f6281a7 /device.c | |
parent | e145ee45e2c2a112629814bcbba6f0e759f5132a (diff) | |
download | vdr-d1ab9dbc5f0c35aa10ee0c67b9dc2eb6fd31dd13.tar.gz vdr-d1ab9dbc5f0c35aa10ee0c67b9dc2eb6fd31dd13.tar.bz2 |
Now checking the result of all realloc() calls
Diffstat (limited to 'device.c')
-rw-r--r-- | device.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: device.c 2.37 2010/06/03 13:35:02 kls Exp $ + * $Id: device.c 2.38 2011/02/25 15:12:03 kls Exp $ */ #include "device.h" @@ -1087,11 +1087,17 @@ void cDevice::StillPicture(const uchar *Data, int Length) int l; while (const uchar *p = TsToPes.GetPes(l)) { int Offset = Size; - Size += l; - buf = (uchar *)realloc(buf, Size); - if (!buf) + int NewSize = Size + l; + if (uchar *NewBuffer = (uchar *)realloc(buf, NewSize)) { + Size = NewSize; + buf = NewBuffer; + memcpy(buf + Offset, p, l); + } + else { + LOG_ERROR_STR("out of memory"); + free(buf); return; - memcpy(buf + Offset, p, l); + } } TsToPes.Reset(); } @@ -1103,11 +1109,17 @@ void cDevice::StillPicture(const uchar *Data, int Length) int l; while (const uchar *p = TsToPes.GetPes(l)) { int Offset = Size; - Size += l; - buf = (uchar *)realloc(buf, Size); - if (!buf) + int NewSize = Size + l; + if (uchar *NewBuffer = (uchar *)realloc(buf, NewSize)) { + Size = NewSize; + buf = NewBuffer; + memcpy(buf + Offset, p, l); + } + else { + esyslog("ERROR: out of memory"); + free(buf); return; - memcpy(buf + Offset, p, l); + } } StillPicture(buf, Size); free(buf); |