Consistently using malloc/free and new/delete

This commit is contained in:
Klaus Schmidinger 2002-08-11 13:32:23 +02:00
parent b9c4cb0ec9
commit 9a1a16f3d4
23 changed files with 172 additions and 160 deletions

View File

@ -158,6 +158,7 @@ Andreas Schultz <aschultz@warp10.net>
than 3 characters
for adding direct access to the index data of cPalette (needed for displaying SPUs)
for pointing out a possible race condition in the cDvbPlayer
for making the use of malloc/free and new/delete consistent
Aaron Holtzman
for writing 'ac3dec'

View File

@ -1401,3 +1401,4 @@ Video Disk Recorder Revision History
- Added some missing #includes (thanks to Martin Hammerschmid).
- Changed the log error message "can't record MPEG1!" to "error in data stream!",
since the mentioning of MPEG1 has irritated many people.
- Consistently using malloc/free and new/delete (thanks to Andreas Schultz).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: config.c 1.103 2002/08/04 12:03:11 kls Exp $
* $Id: config.c 1.104 2002/08/11 11:35:18 kls Exp $
*/
#include "config.h"
@ -217,7 +217,7 @@ const char *cChannel::ToText(cChannel *Channel)
s = strcpy(buf, s);
strreplace(s, ':', '|');
}
delete buffer;
free(buffer);
if (Channel->groupSep)
asprintf(&buffer, ":%s\n", s);
else {
@ -267,7 +267,7 @@ bool cChannel::Parse(const char *s)
sscanf(apidbuf, "%d ,%d ", &apid1, &apid2);
if (p)
sscanf(p, "%d ,%d ", &dpid1, &dpid2);
delete apidbuf;
free(apidbuf);
}
else
return false;
@ -279,7 +279,7 @@ bool cChannel::Parse(const char *s)
tpid = 0;
}
strn0cpy(name, buffer, MaxChannelName);
delete buffer;
free(buffer);
}
else
return false;
@ -377,7 +377,7 @@ cTimer::cTimer(const cEventInfo *EventInfo)
cTimer::~cTimer()
{
delete summary;
free(summary);
}
cTimer& cTimer::operator= (const cTimer &Timer)
@ -398,7 +398,7 @@ bool cTimer::operator< (const cListObject &ListObject)
const char *cTimer::ToText(cTimer *Timer)
{
delete buffer;
free(buffer);
strreplace(Timer->file, ':', '|');
strreplace(Timer->summary, '\n', '|');
asprintf(&buffer, "%d:%d:%s:%04d:%04d:%d:%d:%s:%s\n", Timer->active, Timer->channel, PrintDay(Timer->day, Timer->firstday), Timer->start, Timer->stop, Timer->priority, Timer->lifetime, Timer->file, Timer->summary ? Timer->summary : "");
@ -495,7 +495,7 @@ bool cTimer::Parse(const char *s)
{
char *buffer1 = NULL;
char *buffer2 = NULL;
delete summary;
free(summary);
summary = NULL;
//XXX Apparently sscanf() doesn't work correctly if the last %a argument
//XXX results in an empty string (this first occured when the EIT gathering
@ -508,13 +508,13 @@ bool cTimer::Parse(const char *s)
while (l2 > 0 && isspace(s[l2 - 1]))
l2--;
if (s[l2 - 1] == ':') {
s2 = (char *)malloc(l2 + 3);
s2 = MALLOC(char, l2 + 3);
strcat(strn0cpy(s2, s, l2 + 1), " \n");
s = s2;
}
if (8 <= sscanf(s, "%d :%d :%a[^:]:%d :%d :%d :%d :%a[^:\n]:%a[^\n]", &active, &channel, &buffer1, &start, &stop, &priority, &lifetime, &buffer2, &summary)) {
if (summary && !*skipspace(summary)) {
delete summary;
free(summary);
summary = NULL;
}
//TODO add more plausibility checks
@ -522,12 +522,12 @@ bool cTimer::Parse(const char *s)
strn0cpy(file, buffer2, MaxFileName);
strreplace(file, '|', ':');
strreplace(summary, '|', '\n');
delete buffer1;
delete buffer2;
delete s2;
free(buffer1);
free(buffer2);
free(s2);
return day != 0;
}
delete s2;
free(s2);
return false;
}
@ -661,8 +661,8 @@ cCommand::cCommand(void)
cCommand::~cCommand()
{
delete title;
delete command;
free(title);
free(command);
}
bool cCommand::Parse(const char *s)
@ -685,7 +685,7 @@ bool cCommand::Parse(const char *s)
const char *cCommand::Execute(void)
{
dsyslog("executing command '%s'", command);
delete result;
free(result);
result = NULL;
FILE *p = popen(command, "r");
if (p) {
@ -749,7 +749,7 @@ cCaDefinition::cCaDefinition(void)
cCaDefinition::~cCaDefinition()
{
delete description;
free(description);
}
bool cCaDefinition::Parse(const char *s)
@ -935,9 +935,9 @@ cSetupLine::cSetupLine(const char *Name, const char *Value, const char *Plugin)
cSetupLine::~cSetupLine()
{
delete plugin;
delete name;
delete value;
free(plugin);
free(name);
free(value);
}
bool cSetupLine::operator< (const cListObject &ListObject)
@ -1068,7 +1068,7 @@ void cSetup::Store(const char *Name, int Value, const char *Plugin)
char *buffer = NULL;
asprintf(&buffer, "%d", Value);
Store(Name, buffer, Plugin);
delete buffer;
free(buffer);
}
bool cSetup::Load(const char *FileName)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: config.h 1.122 2002/08/09 14:53:21 kls Exp $
* $Id: config.h 1.123 2002/08/11 11:36:36 kls Exp $
*/
#ifndef __CONFIG_H
@ -12,6 +12,7 @@
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@ -214,12 +215,13 @@ private:
char *fileName;
void Clear(void)
{
delete fileName;
free(fileName);
fileName = NULL;
cList<T>::Clear();
}
public:
cConfig(void) { fileName = NULL; }
virtual ~cConfig() { delete fileName; }
virtual ~cConfig() { free(fileName); }
const char *FileName(void) { return fileName; }
bool Load(const char *FileName, bool AllowComments = false)
{

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: cutter.c 1.1 2002/06/22 10:09:34 kls Exp $
* $Id: cutter.c 1.2 2002/08/11 11:09:23 kls Exp $
*/
#include "cutter.h"
@ -196,7 +196,7 @@ bool cCutter::Start(const char *FileName)
RemoveVideoFile(s);
}
}
delete s;
free(s);
// XXX
editedVersionName = strdup(evn);
Recording.WriteSummary();
@ -231,7 +231,7 @@ bool cCutter::Active(void)
Stop();
if (!error)
cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName);
delete editedVersionName;
free(editedVersionName);
editedVersionName = NULL;
ended = true;
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: dvbdevice.c 1.2 2002/08/10 14:57:33 kls Exp $
* $Id: dvbdevice.c 1.3 2002/08/11 12:03:33 kls Exp $
*/
#include "dvbdevice.h"
@ -316,6 +316,7 @@ bool cDvbDevice::SetPid(cPidHandle *Handle, int Type, bool On)
if (Handle->pid != 0x1FFF) {
dmxPesFilterParams pesFilterParams;
memset(&pesFilterParams, 0, sizeof(pesFilterParams));
pesFilterParams.pid = Handle->pid;
pesFilterParams.input = DMX_IN_FRONTEND;
pesFilterParams.output = (Type <= ptTeletext && Handle->used <= 1) ? DMX_OUT_DECODER : DMX_OUT_TS_TAP;
@ -364,6 +365,8 @@ bool cDvbDevice::SetChannelDevice(const cChannel *Channel)
FrontendParameters Frontend;
#endif
memset(&Frontend, 0, sizeof(Frontend));
switch (frontendType) {
case FE_QPSK: { // DVB-S

18
eit.c
View File

@ -16,7 +16,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* $Id: eit.c 1.47 2002/08/09 16:17:14 kls Exp $
* $Id: eit.c 1.48 2002/08/11 11:11:12 kls Exp $
***************************************************************************/
#include "eit.h"
@ -202,9 +202,9 @@ cEventInfo::cEventInfo(unsigned short serviceid, unsigned short eventid)
cEventInfo::~cEventInfo()
{
delete pTitle;
delete pSubtitle;
delete pExtendedDescription;
free(pTitle);
free(pSubtitle);
free(pExtendedDescription);
}
/** */
@ -500,8 +500,8 @@ void cEventInfo::FixEpgBugs(void)
*e = 0;
char *s = strdup(p + 1);
char *d = strdup(e + strlen(delim));
delete pSubtitle;
delete pExtendedDescription;
free(pSubtitle);
free(pExtendedDescription);
pSubtitle = s;
pExtendedDescription = d;
EpgBugFixStat(0, GetServiceID());
@ -531,7 +531,7 @@ void cEventInfo::FixEpgBugs(void)
// Title
//
if (pSubtitle && strcmp(pTitle, pSubtitle) == 0) {
delete pSubtitle;
free(pSubtitle);
pSubtitle = NULL;
EpgBugFixStat(2, GetServiceID());
}
@ -1001,10 +1001,10 @@ cSIProcessor::~cSIProcessor()
active = false;
Cancel(3);
ShutDownFilters();
delete filters;
free(filters);
if (!--numSIProcessors) // the last one deletes it
delete schedules;
delete fileName;
free(fileName);
}
const cSchedules *cSIProcessor::Schedules(cMutexLock &MutexLock)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: eitscan.c 1.4 2002/07/28 15:10:23 kls Exp $
* $Id: eitscan.c 1.5 2002/08/11 11:11:39 kls Exp $
*/
#include "eitscan.h"
@ -21,7 +21,7 @@ cEITScanner::cEITScanner(void)
cEITScanner::~cEITScanner()
{
delete transponders;
free(transponders);
}
bool cEITScanner::TransponderScanned(cChannel *Channel)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: interface.c 1.53 2002/08/11 10:47:04 kls Exp $
* $Id: interface.c 1.54 2002/08/11 11:46:47 kls Exp $
*/
#include "interface.h"
@ -85,7 +85,7 @@ eKeys cInterface::GetKey(bool Wait)
char *message = SVDRP->GetMessage();
if (message) {
Info(message);
delete message;
free(message);
}
}
}
@ -214,12 +214,12 @@ char *cInterface::WrapText(const char *Text, int Width, int *Height)
// punch in a newline, so we need to make room for it:
if (Delim)
p = Delim + 1; // let's fall back to the most recent delimiter
char *s = new char[strlen(t) + 2]; // The additional '\n' plus the terminating '\0'
char *s = MALLOC(char, strlen(t) + 2); // The additional '\n' plus the terminating '\0'
int l = p - t;
strncpy(s, t, l);
s[l] = '\n';
strcpy(s + l + 1, p);
delete t;
free(t);
t = s;
p = t + l;
continue;
@ -400,7 +400,7 @@ void cInterface::QueryKeys(void)
char *Prompt;
asprintf(&Prompt, tr("Press key for '%s'"), tr(k->name));
WriteText(1, 5, Prompt);
delete Prompt;
free(Prompt);
for (;;) {
unsigned int ch = GetCh();
if (ch != 0) {

42
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menu.c 1.203 2002/08/03 09:55:44 kls Exp $
* $Id: menu.c 1.204 2002/08/11 11:50:20 kls Exp $
*/
#include "menu.h"
@ -936,7 +936,7 @@ cMenuEvent::cMenuEvent(const cEventInfo *EventInfo, bool CanSwitch)
char *buffer;
asprintf(&buffer, "%-17.*s\t%.*s %s - %s", 17, channel->name, 5, eventInfo->GetDate(), eventInfo->GetTimeString(), eventInfo->GetEndTimeString());
SetTitle(buffer, false);
delete buffer;
free(buffer);
int Line = 2;
cMenuTextItem *item;
const char *Title = eventInfo->GetTitle();
@ -1040,7 +1040,7 @@ cMenuWhatsOn::cMenuWhatsOn(const cSchedules *Schedules, bool Now, int CurrentCha
Add(new cMenuWhatsOnItem(pArray[a]), pArray[a]->GetChannelNumber() == CurrentChannelNr);
currentChannel = CurrentChannelNr;
delete pArray;
free(pArray);
SetHelp(tr("Record"), Now ? tr("Next") : tr("Now"), tr("Button$Schedule"), tr("Switch"));
}
@ -1173,11 +1173,11 @@ void cMenuSchedule::PrepareSchedule(cChannel *Channel)
char *buffer = NULL;
asprintf(&buffer, tr("Schedule - %s"), Channel->name);
SetTitle(buffer);
delete buffer;
free(buffer);
if (schedules) {
const cSchedule *Schedule = Channel->pnr ? schedules->GetSchedule(Channel->pnr) : schedules->GetSchedule();
int num = Schedule->NumEvents();
const cEventInfo **pArray = (const cEventInfo **)malloc(num * sizeof(cEventInfo *));
const cEventInfo **pArray = MALLOC(const cEventInfo *, num);
if (pArray) {
time_t now = time(NULL);
int numreal = 0;
@ -1191,7 +1191,7 @@ void cMenuSchedule::PrepareSchedule(cChannel *Channel)
for (int a = 0; a < numreal; a++)
Add(new cMenuScheduleItem(pArray[a]));
delete pArray;
free(pArray);
}
}
}
@ -1306,8 +1306,8 @@ cMenuRecordingItem::cMenuRecordingItem(cRecording *Recording, int Level)
cMenuRecordingItem::~cMenuRecordingItem()
{
delete fileName;
delete name;
free(fileName);
free(name);
}
void cMenuRecordingItem::IncrementCounter(bool New)
@ -1344,7 +1344,7 @@ cMenuRecordings::cMenuRecordings(const char *Base, int Level, bool OpenSubMenus)
if (*Item->Text() && (!LastItem || strcmp(Item->Text(), LastItemText) != 0)) {
Add(Item);
LastItem = Item;
delete LastItemText;
free(LastItemText);
LastItemText = strdup(LastItem->Text()); // must use a copy because of the counters!
}
else
@ -1357,7 +1357,7 @@ cMenuRecordings::cMenuRecordings(const char *Base, int Level, bool OpenSubMenus)
}
}
}
delete LastItemText;
free(LastItemText);
if (Current() < 0)
SetCurrent(First());
else if (OpenSubMenus && Open(true))
@ -1370,7 +1370,7 @@ cMenuRecordings::cMenuRecordings(const char *Base, int Level, bool OpenSubMenus)
cMenuRecordings::~cMenuRecordings()
{
helpKeys = -1;
delete base;
free(base);
}
void cMenuRecordings::SetHelpKeys(void)
@ -1417,7 +1417,7 @@ bool cMenuRecordings::Open(bool OpenSubMenus)
t = buffer;
}
AddSubMenu(new cMenuRecordings(t, level + 1, OpenSubMenus));
delete buffer;
free(buffer);
return true;
}
return false;
@ -1766,7 +1766,7 @@ cMenuSetupPlugins::cMenuSetupPlugins(void)
char *buffer = NULL;
asprintf(&buffer, "%s (%s) - %s", p->Name(), p->Version(), p->Description());
Add(new cMenuSetupPluginItem(hk(buffer), i));
delete buffer;
free(buffer);
}
else
break;
@ -1901,7 +1901,7 @@ eOSState cMenuCommands::Execute(void)
asprintf(&buffer, "%s...", command->Title());
Interface->Status(buffer);
Interface->Flush();
delete buffer;
free(buffer);
const char *Result = command->Execute();
if (Result)
return AddSubMenu(new cMenuText(command->Title(), Result, fontFix));
@ -2013,7 +2013,7 @@ void cMenuMain::Set(void)
char *buffer = NULL;
asprintf(&buffer, "%s%s", STOP_RECORDING, ON_PRIMARY_INTERFACE);
Add(new cOsdItem(buffer, osStopRecord));
delete buffer;
free(buffer);
}
const char *s = NULL;
@ -2021,7 +2021,7 @@ void cMenuMain::Set(void)
char *buffer = NULL;
asprintf(&buffer, "%s%s", STOP_RECORDING, s);
Add(new cOsdItem(buffer, osStopRecord));
delete buffer;
free(buffer);
}
// Editing control:
@ -2452,8 +2452,8 @@ cRecordControl::cRecordControl(cDevice *Device, cTimer *Timer)
cRecordControl::~cRecordControl()
{
Stop(true);
delete instantId;
delete fileName;
free(instantId);
free(fileName);
}
#define INSTANT_REC_EPG_LOOKAHEAD 300 // seconds to look into the EPG data for an instant recording
@ -2701,8 +2701,8 @@ cReplayControl::~cReplayControl()
void cReplayControl::SetRecording(const char *FileName, const char *Title)
{
delete fileName;
delete title;
free(fileName);
free(title);
fileName = FileName ? strdup(FileName) : NULL;
title = Title ? strdup(Title) : NULL;
}
@ -2715,7 +2715,7 @@ const char *cReplayControl::LastReplayed(void)
void cReplayControl::ClearLastReplayed(const char *FileName)
{
if (fileName && FileName && strcmp(fileName, FileName) == 0) {
delete fileName;
free(fileName);
fileName = NULL;
}
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menuitems.c 1.6 2002/06/16 13:23:56 kls Exp $
* $Id: menuitems.c 1.7 2002/08/11 11:17:21 kls Exp $
*/
#include "menuitems.h"
@ -23,13 +23,13 @@ cMenuEditItem::cMenuEditItem(const char *Name)
cMenuEditItem::~cMenuEditItem()
{
delete name;
delete value;
free(name);
free(value);
}
void cMenuEditItem::SetValue(const char *Value)
{
delete value;
free(value);
value = strdup(Value);
char *buffer = NULL;
asprintf(&buffer, "%s:\t%s", name, value);
@ -119,7 +119,7 @@ cMenuEditChrItem::cMenuEditChrItem(const char *Name, char *Value, const char *Al
cMenuEditChrItem::~cMenuEditChrItem()
{
delete allowed;
free(allowed);
}
void cMenuEditChrItem::Set(void)
@ -167,7 +167,7 @@ cMenuEditStrItem::cMenuEditStrItem(const char *Name, char *Value, int Length, co
cMenuEditStrItem::~cMenuEditStrItem()
{
delete allowed;
free(allowed);
}
void cMenuEditStrItem::SetHelpKeys(void)
@ -364,7 +364,7 @@ cMenuTextItem::cMenuTextItem(const char *Text, int X, int Y, int W, int H, eDvbC
cMenuTextItem::~cMenuTextItem()
{
delete text;
free(text);
}
void cMenuTextItem::Clear(void)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menuitems.h 1.2 2002/05/11 10:48:28 kls Exp $
* $Id: menuitems.h 1.3 2002/08/11 11:40:05 kls Exp $
*/
#ifndef __MENUITEMS_H
@ -14,8 +14,8 @@
class cMenuEditItem : public cOsdItem {
private:
const char *name;
const char *value;
char *name;
char *value;
public:
cMenuEditItem(const char *Name);
~cMenuEditItem();
@ -43,7 +43,7 @@ public:
class cMenuEditChrItem : public cMenuEditItem {
private:
char *value;
const char *allowed;
char *allowed;
const char *current;
virtual void Set(void);
public:
@ -56,7 +56,7 @@ class cMenuEditStrItem : public cMenuEditItem {
private:
char *value;
int length;
const char *allowed;
char *allowed;
int pos;
bool insert, newchar, uppercase;
void SetHelpKeys(void);

16
osd.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: osd.c 1.32 2002/08/04 10:11:26 kls Exp $
* $Id: osd.c 1.33 2002/08/11 11:43:22 kls Exp $
*/
#include "osd.h"
@ -279,13 +279,13 @@ cOsdItem::cOsdItem(const char *Text, eOSState State)
cOsdItem::~cOsdItem()
{
delete text;
free(text);
}
void cOsdItem::SetText(const char *Text, bool Copy)
{
delete text;
text = Copy ? strdup(Text) : Text;
free(text);
text = Copy ? strdup(Text) : (char *)Text; // text assumes ownership!
}
void cOsdItem::SetColor(eDvbColor FgColor, eDvbColor BgColor)
@ -337,9 +337,9 @@ cOsdMenu::cOsdMenu(const char *Title, int c0, int c1, int c2, int c3, int c4)
cOsdMenu::~cOsdMenu()
{
delete title;
free(title);
delete subMenu;
delete status;
free(status);
Interface->Clear();
Interface->Close();
}
@ -367,7 +367,7 @@ void cOsdMenu::SetHasHotkeys(void)
void cOsdMenu::SetStatus(const char *s)
{
delete status;
free(status);
status = s ? strdup(s) : NULL;
if (visible)
Interface->Status(status);
@ -375,7 +375,7 @@ void cOsdMenu::SetStatus(const char *s)
void cOsdMenu::SetTitle(const char *Title, bool ShowDate)
{
delete title;
free(title);
if (ShowDate)
asprintf(&title, "%s\t%s", Title, DayDateTime(time(NULL)));
else

6
osd.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: osd.h 1.33 2002/07/13 12:47:06 kls Exp $
* $Id: osd.h 1.34 2002/08/11 11:42:15 kls Exp $
*/
#ifndef __OSD_H
@ -89,7 +89,7 @@ public:
class cOsdItem : public cListObject {
private:
const char *text;
char *text;
int offset;
eOSState state;
protected:
@ -128,7 +128,7 @@ private:
int first, current, marked;
cOsdMenu *subMenu;
const char *helpRed, *helpGreen, *helpYellow, *helpBlue;
const char *status;
char *status;
int digit;
bool hasHotkeys;
protected:

View File

@ -4,11 +4,12 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: osdbase.c 1.5 2002/07/13 14:42:47 kls Exp $
* $Id: osdbase.c 1.6 2002/08/11 11:47:21 kls Exp $
*/
#include "osdbase.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/unistd.h>
@ -109,7 +110,7 @@ cBitmap::cBitmap(int Width, int Height, int Bpp, bool ClearWithBackground)
fontType = fontOsd;
font = NULL;
if (width > 0 && height > 0) {
bitmap = new char[width * height];
bitmap = MALLOC(char, width * height);
if (bitmap) {
Clean();
memset(bitmap, 0x00, width * height);
@ -125,7 +126,7 @@ cBitmap::cBitmap(int Width, int Height, int Bpp, bool ClearWithBackground)
cBitmap::~cBitmap()
{
delete font;
delete bitmap;
free(bitmap);
}
eDvbFont cBitmap::SetFont(eDvbFont Font)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: plugin.c 1.6 2002/08/11 10:47:11 kls Exp $
* $Id: plugin.c 1.7 2002/08/11 11:21:00 kls Exp $
*/
#include "plugin.h"
@ -102,7 +102,7 @@ void cPlugin::SetConfigDirectory(const char *Dir)
const char *cPlugin::ConfigDirectory(const char *PluginName)
{
static char *buffer = NULL;
delete buffer;
free(buffer);
asprintf(&buffer, "%s/plugins%s%s", configDirectory, PluginName ? "/" : "", PluginName ? PluginName : "");
return MakeDirs(buffer, true) ? buffer : NULL;
}
@ -122,8 +122,8 @@ cDll::~cDll()
delete plugin;
if (handle)
dlclose(handle);
delete args;
delete fileName;
free(args);
free(fileName);
}
static char *SkipQuote(char *s)
@ -237,14 +237,14 @@ cPluginManager::cPluginManager(const char *Directory)
cPluginManager::~cPluginManager()
{
Shutdown();
delete directory;
free(directory);
if (pluginManager == this)
pluginManager = NULL;
}
void cPluginManager::SetDirectory(const char *Directory)
{
delete directory;
free(directory);
directory = Directory ? strdup(Directory) : NULL;
}
@ -280,8 +280,8 @@ void cPluginManager::AddPlugin(const char *Args)
char *buffer = NULL;
asprintf(&buffer, "%s/%s%s%s%s", directory, LIBVDR_PREFIX, s, SO_INDICATOR, VDRVERSION);
dlls.Add(new cDll(buffer, Args));
delete buffer;
delete s;
free(buffer);
free(s);
}
bool cPluginManager::LoadPlugins(bool Log)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: recording.c 1.65 2002/07/27 12:55:14 kls Exp $
* $Id: recording.c 1.66 2002/08/11 11:48:11 kls Exp $
*/
#include "recording.h"
@ -148,7 +148,7 @@ void AssertFreeDiskSpace(int Priority)
cResumeFile::cResumeFile(const char *FileName)
{
fileName = new char[strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1];
fileName = MALLOC(char, strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1);
if (fileName) {
strcpy(fileName, FileName);
strcat(fileName, RESUMEFILESUFFIX);
@ -159,7 +159,7 @@ cResumeFile::cResumeFile(const char *FileName)
cResumeFile::~cResumeFile()
{
delete fileName;
free(fileName);
}
int cResumeFile::Read(void)
@ -375,7 +375,7 @@ cRecording::cRecording(const char *FileName)
struct stat buf;
if (fstat(f, &buf) == 0) {
int size = buf.st_size;
summary = new char[size + 1]; // +1 for terminating 0
summary = MALLOC(char, size + 1); // +1 for terminating 0
if (summary) {
int rbytes = safe_read(f, summary, size);
if (rbytes >= 0) {
@ -385,7 +385,7 @@ cRecording::cRecording(const char *FileName)
}
else {
LOG_ERROR_STR(SummaryFileName);
delete summary;
free(summary);
summary = NULL;
}
@ -399,17 +399,17 @@ cRecording::cRecording(const char *FileName)
}
else if (errno != ENOENT)
LOG_ERROR_STR(SummaryFileName);
delete SummaryFileName;
free(SummaryFileName);
}
}
cRecording::~cRecording()
{
delete titleBuffer;
delete sortBuffer;
delete fileName;
delete name;
delete summary;
free(titleBuffer);
free(sortBuffer);
free(fileName);
free(name);
free(summary);
}
char *cRecording::StripEpisodeName(char *s)
@ -437,9 +437,9 @@ char *cRecording::SortName(void)
if (!sortBuffer) {
char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1));
int l = strxfrm(NULL, s, 0);
sortBuffer = new char[l];
sortBuffer = MALLOC(char, l);
strxfrm(sortBuffer, s, l);
delete s;
free(s);
}
return sortBuffer;
}
@ -474,7 +474,7 @@ const char *cRecording::FileName(void)
const char *cRecording::Title(char Delimiter, bool NewIndicator, int Level)
{
char New = NewIndicator && IsNew() ? '*' : ' ';
delete titleBuffer;
free(titleBuffer);
titleBuffer = NULL;
if (Level < 0 || Level == HierarchyLevels()) {
struct tm tm_r;
@ -524,7 +524,7 @@ const char *cRecording::PrefixFileName(char Prefix)
{
const char *p = PrefixVideoFileName(FileName(), Prefix);
if (p) {
delete fileName;
free(fileName);
fileName = strdup(p);
return fileName;
}
@ -555,7 +555,7 @@ bool cRecording::WriteSummary(void)
}
else
LOG_ERROR_STR(SummaryFileName);
delete SummaryFileName;
free(SummaryFileName);
}
return true;
}
@ -575,7 +575,7 @@ bool cRecording::Delete(void)
isyslog("deleting recording %s", FileName());
result = RenameVideoFile(FileName(), NewName);
}
delete NewName;
free(NewName);
return result;
}
@ -614,7 +614,7 @@ bool cRecordings::Load(bool Deleted)
}
else
Interface->Error("Error while opening pipe!");
delete cmd;
free(cmd);
return result;
}
@ -639,19 +639,19 @@ cMark::cMark(int Position, const char *Comment)
cMark::~cMark()
{
delete comment;
free(comment);
}
const char *cMark::ToText(void)
{
delete buffer;
free(buffer);
asprintf(&buffer, "%s%s%s\n", IndexToHMSF(position, true), comment ? " " : "", comment ? comment : "");
return buffer;
}
bool cMark::Parse(const char *s)
{
delete comment;
free(comment);
comment = NULL;
position = HMSFToIndex(s);
const char *p = strchr(s, ' ');
@ -742,7 +742,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi
asprintf(&cmd, "%s %s \"%s\"", command, State, strescape(RecordingFileName, "\"$"));
isyslog("executing '%s'", cmd);
SystemExec(cmd);
delete cmd;
free(cmd);
}
}
@ -782,13 +782,13 @@ cIndexFile::cIndexFile(const char *FileName, bool Record)
last = (buf.st_size + delta) / sizeof(tIndex) - 1;
if (!Record && last >= 0) {
size = last + 1;
index = new tIndex[size];
index = MALLOC(tIndex, size);
if (index) {
f = open(fileName, O_RDONLY);
if (f >= 0) {
if ((int)safe_read(f, index, buf.st_size) != buf.st_size) {
esyslog("ERROR: can't read from file '%s'", fileName);
delete index;
free(index);
index = NULL;
close(f);
f = -1;
@ -828,8 +828,8 @@ cIndexFile::~cIndexFile()
{
if (f >= 0)
close(f);
delete fileName;
delete index;
free(fileName);
free(index);
}
bool cIndexFile::CatchUp(int Index)
@ -852,7 +852,7 @@ bool cIndexFile::CatchUp(int Index)
if (lseek(f, offset, SEEK_SET) == offset) {
if (safe_read(f, &index[last + 1], delta) != delta) {
esyslog("ERROR: can't read from index");
delete index;
free(index);
index = NULL;
close(f);
f = -1;
@ -999,7 +999,7 @@ cFileName::cFileName(const char *FileName, bool Record, bool Blocking)
cFileName::~cFileName()
{
Close();
delete fileName;
free(fileName);
}
int cFileName::Open(void)

View File

@ -8,7 +8,7 @@
* the Linux DVB driver's 'tuxplayer' example and were rewritten to suit
* VDR's needs.
*
* $Id: remux.c 1.10 2002/08/11 10:53:10 kls Exp $
* $Id: remux.c 1.11 2002/08/11 11:48:34 kls Exp $
*/
/* The calling interface of the 'cRemux::Process()' function is defined
@ -66,6 +66,7 @@
*/
#include "remux.h"
#include <stdlib.h>
#include "thread.h"
#include "tools.h"
@ -153,7 +154,7 @@ cTS2PES::cTS2PES(uint8_t *ResultBuffer, int *ResultCount, int Size, uint8_t Audi
size = Size;
audioCid = AudioCid;
if (!(buf = new uint8_t[size]))
if (!(buf = MALLOC(uint8_t, size)))
esyslog("Not enough memory for ts_transform");
reset_ipack();
@ -161,7 +162,7 @@ cTS2PES::cTS2PES(uint8_t *ResultBuffer, int *ResultCount, int Size, uint8_t Audi
cTS2PES::~cTS2PES()
{
delete buf;
free(buf);
}
void cTS2PES::Clear(void)

11
svdrp.c
View File

@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection.
*
* $Id: svdrp.c 1.38 2002/06/10 16:30:00 kls Exp $
* $Id: svdrp.c 1.39 2002/08/11 12:01:28 kls Exp $
*/
#include "svdrp.h"
@ -37,6 +37,7 @@ cSocket::cSocket(int Port, int Queue)
{
port = Port;
sock = -1;
queue = Queue;
}
cSocket::~cSocket()
@ -320,7 +321,7 @@ cSVDRP::cSVDRP(int Port)
cSVDRP::~cSVDRP()
{
Close();
delete message;
free(message);
}
void cSVDRP::Close(bool Timeout)
@ -370,7 +371,7 @@ void cSVDRP::Reply(int Code, const char *fmt, ...)
}
s = n ? n + 1 : NULL;
}
delete buffer;
free(buffer);
va_end(ap);
}
else {
@ -685,7 +686,7 @@ void cSVDRP::CmdLSTR(const char *Option)
if (recording->Summary()) {
char *summary = strdup(recording->Summary());
Reply(250, "%s", strreplace(summary,'\n','|'));
delete summary;
free(summary);
}
else
Reply(550, "No summary availabe");
@ -736,7 +737,7 @@ void cSVDRP::CmdLSTT(const char *Option)
void cSVDRP::CmdMESG(const char *Option)
{
if (*Option) {
delete message;
free(message);
message = strdup(Option);
isyslog("SVDRP message: '%s'", message);
Reply(250, "Message stored");

28
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 1.68 2002/08/03 15:44:53 kls Exp $
* $Id: tools.c 1.69 2002/08/11 11:49:08 kls Exp $
*/
#include "tools.h"
@ -80,7 +80,7 @@ char *strcpyrealloc(char *dest, const char *src)
esyslog("ERROR: out of memory");
}
else {
delete dest;
free(dest);
dest = NULL;
}
return dest;
@ -239,7 +239,7 @@ bool isnumber(const char *s)
const char *AddDirectory(const char *DirName, const char *FileName)
{
static char *buf = NULL;
delete buf;
free(buf);
asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName);
return buf;
}
@ -303,7 +303,7 @@ bool MakeDirs(const char *FileName, bool IsDirectory)
else
break;
}
delete s;
free(s);
return result;
}
@ -321,7 +321,7 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
asprintf(&buffer, "%s/%s", FileName, e->d_name);
if (FollowSymlinks) {
int size = strlen(buffer) * 2; // should be large enough
char *l = new char[size];
char *l = MALLOC(char, size);
int n = readlink(buffer, l, size);
if (n < 0) {
if (errno != EINVAL)
@ -335,12 +335,12 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
}
else
esyslog("ERROR: symlink name length (%d) exceeded anticipated buffer size (%d)", n, size);
delete l;
free(l);
}
dsyslog("removing %s", buffer);
if (remove(buffer) < 0)
LOG_ERROR_STR(buffer);
delete buffer;
free(buffer);
}
}
closedir(d);
@ -384,10 +384,10 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
}
else {
LOG_ERROR_STR(buffer);
delete buffer;
free(buffer);
return false;
}
delete buffer;
free(buffer);
}
}
closedir(d);
@ -429,7 +429,7 @@ bool SpinUpDisk(const char *FileName)
{
static char *buf = NULL;
for (int n = 0; n < 10; n++) {
delete buf;
free(buf);
if (DirectoryOk(FileName))
asprintf(&buf, "%s/vdr-%06d", *FileName ? FileName : ".", n);
else
@ -594,7 +594,7 @@ cSafeFile::cSafeFile(const char *FileName)
{
f = NULL;
fileName = ReadLink(FileName);
tempName = fileName ? new char[strlen(fileName) + 5] : NULL;
tempName = fileName ? MALLOC(char, strlen(fileName) + 5) : NULL;
if (tempName)
strcat(strcpy(tempName, fileName), ".$$$");
}
@ -604,8 +604,8 @@ cSafeFile::~cSafeFile()
if (f)
fclose(f);
unlink(tempName);
delete fileName;
delete tempName;
free(fileName);
free(tempName);
}
bool cSafeFile::Open(void)
@ -657,7 +657,7 @@ cLockFile::cLockFile(const char *Directory)
cLockFile::~cLockFile()
{
Unlock();
delete fileName;
free(fileName);
}
bool cLockFile::Lock(int WaitSeconds)

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.h 1.47 2002/06/10 16:30:00 kls Exp $
* $Id: tools.h 1.48 2002/08/11 11:34:26 kls Exp $
*/
#ifndef __TOOLS_H
@ -36,6 +36,8 @@ extern int SysLogLevel;
#define MAXPARSEBUFFER KILOBYTE(10)
#define MALLOC(type, size) (type *)malloc(sizeof(type) * (size))
#define DELETENULL(p) (delete (p), p = NULL)
#define CHECK(s) { if ((s) < 0) LOG_ERROR; } // used for 'ioctl()' calls

6
vdr.c
View File

@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/people/kls/vdr
*
* $Id: vdr.c 1.118 2002/08/04 09:56:30 kls Exp $
* $Id: vdr.c 1.119 2002/08/11 11:32:15 kls Exp $
*/
#include <getopt.h>
@ -585,7 +585,7 @@ int main(int argc, char *argv[])
asprintf(&buf, tr("Recording in %d minutes, shut down anyway?"), Delta / 60);
if (Interface->Confirm(buf))
ForceShutdown = true;
delete buf;
free(buf);
}
if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) {
ForceShutdown = false;
@ -600,7 +600,7 @@ int main(int argc, char *argv[])
asprintf(&cmd, "%s %ld %ld %d \"%s\" %d", Shutdown, Next, Delta, Channel, strescape(File, "\"$"), UserShutdown);
isyslog("executing '%s'", cmd);
SystemExec(cmd);
delete cmd;
free(cmd);
}
else if (WatchdogTimeout > 0) {
alarm(WatchdogTimeout);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: videodir.c 1.8 2002/05/13 16:32:52 kls Exp $
* $Id: videodir.c 1.9 2002/08/11 13:31:02 kls Exp $
*/
#include "videodir.h"
@ -48,9 +48,9 @@ cVideoDirectory::cVideoDirectory(void)
cVideoDirectory::~cVideoDirectory()
{
delete name;
delete stored;
delete adjusted;
free(name);
free(stored);
free(adjusted);
}
int cVideoDirectory::FreeMB(int *UsedMB)
@ -87,7 +87,7 @@ bool cVideoDirectory::Next(void)
void cVideoDirectory::Store(void)
{
if (name) {
delete stored;
free(stored);
stored = strdup(name);
}
}
@ -95,7 +95,7 @@ void cVideoDirectory::Store(void)
const char *cVideoDirectory::Adjust(const char *FileName)
{
if (stored) {
delete adjusted;
free(adjusted);
adjusted = strdup(FileName);
return strncpy(adjusted, stored, length);
}
@ -139,7 +139,7 @@ int OpenVideoFile(const char *FileName, int Flags)
}
int Result = open(ActualFileName, Flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (ActualFileName != FileName)
delete ActualFileName;
free((char *)ActualFileName);
return Result;
}