Browse Source

fix a few memleaks

- delete [] must be used when mem is allocated with new []
master
Olaf Rempel 16 years ago
parent
commit
2fd676eb7d
  1. 3
      config.cpp
  2. 15
      logging.cpp
  3. 2
      logging.h
  4. 4
      multisock.cpp
  5. 4
      netpkt.cpp

3
config.cpp

@ -141,6 +141,7 @@ bool Config::parseFile(const char* name)
if (!(fz = fopen(name, "r"))) {
LogSystem::log(LOG_ERROR, "config_parse(): can not open %s", name);
delete [] row;
return false;
}
@ -179,7 +180,7 @@ bool Config::parseFile(const char* name)
}
fclose(fz);
delete row;
delete [] row;
return ret;
}

15
logging.cpp

@ -7,18 +7,13 @@
#include "logging.h"
/* we need this for packet dumps! */
#define BUFLEN 8192
LogSystem::LogSystem() : output(0), priority(0)
LogSystem::LogSystem()
: output(0), priority(0)
{
buffer = new char[BUFLEN];
}
LogSystem::~LogSystem()
{
delete buffer;
if (output)
delete output;
}
@ -76,13 +71,13 @@ void LogSystem::log(int prio, const char* fmt, ...)
int len;
va_start(az, fmt);
len = vsnprintf(ls->buffer, BUFLEN, fmt, az);
len = vsnprintf(ls->buffer, sizeof(ls->buffer), fmt, az);
va_end(az);
if (errno) {
strncpy(ls->buffer + len, ": ", BUFLEN - len);
strncpy(ls->buffer + len, ": ", sizeof(ls->buffer) - len);
len += 2;
strncpy(ls->buffer + len, strerror(errno), BUFLEN - len);
strncpy(ls->buffer + len, strerror(errno), sizeof(ls->buffer) - len);
errno = 0;
}

2
logging.h

@ -42,7 +42,7 @@ private:
LogOutput *output;
int priority;
char* buffer;
char buffer[8192]; // we need this for (large) packet dumps!
};
class StdErrLog : public LogOutput {

4
multisock.cpp

@ -28,7 +28,7 @@ MultiSock::MultiSock(Config& conf)
FILE* fp = fopen(DEVFILE, "r");
if (fp == NULL) {
LogSystem::log(LOG_CRIT, "MultiSock(): can not open " DEVFILE);
free(buf);
delete [] buf;
return;
}
@ -66,7 +66,7 @@ MultiSock::MultiSock(Config& conf)
delete it;
fclose(fp);
delete buf;
delete [] buf;
if (ifaceList.isEmpty())
LogSystem::log(LOG_CRIT, "No useable Interfaces found!");

4
netpkt.cpp

@ -33,7 +33,7 @@ NetPkt::NetPkt(int alloc)
NetPkt::~NetPkt()
{
if (alloc > 0)
delete data;
delete [] data;
}
int NetPkt::show(char* buf, int size)
@ -170,7 +170,7 @@ void NetPkt::merge(NetPkt* pkt)
memcpy(new_data, data, size);
if (alloc)
delete data;
delete [] data;
data = new_data;
alloc = new_alloc;

Loading…
Cancel
Save