mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Consistently using malloc/free and new/delete
This commit is contained in:
28
tools.c
28
tools.c
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user