My code really need that free(NULL) is valid BBrox... =)

And arisme you were SOO right! How was my code working before?!?

svn-id: r4171
This commit is contained in:
Nicolas Noble 2002-05-02 00:46:12 +00:00
parent 97880e239a
commit cfd1ca5fe1

View file

@ -28,6 +28,9 @@
#define MAXLINELEN 256 #define MAXLINELEN 256
#define xfree(p) {if (p) free(p);}
static char *ltrim(char *t) static char *ltrim(char *t)
{ {
for (; *t && (*t == ' '); t++); for (; *t && (*t == ' '); t++);
@ -72,7 +75,7 @@ keys(0), values(0), nkeys(0)
hashconfig::~hashconfig() hashconfig::~hashconfig()
{ {
free(domain); xfree(domain);
} }
bool hashconfig::is_domain(const char *d) const bool hashconfig::is_domain(const char *d) const
@ -99,7 +102,7 @@ const char *hashconfig::set(const char *key, const char *value)
for (i = 0; i < nkeys; i++) { for (i = 0; i < nkeys; i++) {
if (!strcmp(key, keys[i])) { if (!strcmp(key, keys[i])) {
free(values[i]); xfree(values[i]);
return values[i] = value ? Scumm::Strdup(value) : 0; return values[i] = value ? Scumm::Strdup(value) : 0;
} }
} }
@ -135,7 +138,7 @@ void hashconfig::flush(FILE * cfg_file) const
void hashconfig::rename(const char *d) void hashconfig::rename(const char *d)
{ {
free(domain); xfree(domain);
domain = d ? Scumm::Strdup(d) : 0; domain = d ? Scumm::Strdup(d) : 0;
} }
@ -208,13 +211,13 @@ Config::~Config()
{ {
int i; int i;
free(filename); xfree(filename);
free(domain); xfree(domain);
for (i = 0; i < ndomains; i++) { for (i = 0; i < ndomains; i++) {
delete hash[i]; delete hash[i];
} }
free(hash); xfree(hash);
} }
const char *Config::get(const char *key, const char *d) const const char *Config::get(const char *key, const char *d) const
@ -281,7 +284,7 @@ const char *Config::set(const char *key, int value_i, const char *d)
void Config::set_domain(const char *d) void Config::set_domain(const char *d)
{ {
int i; int i;
free(domain); xfree(domain);
domain = d ? Scumm::Strdup(d) : 0; domain = d ? Scumm::Strdup(d) : 0;
for (i = 0; i < ndomains; i++) { for (i = 0; i < ndomains; i++) {
@ -346,7 +349,7 @@ void Config::delete_domain(const char *d)
void Config::change_filename(const char *f) void Config::change_filename(const char *f)
{ {
free(filename); xfree(filename);
filename = f ? Scumm::Strdup(f) : 0; filename = f ? Scumm::Strdup(f) : 0;
} }