From 5d66d73bc33bc16246f9519a70215554bcd2d0ce Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 28 Jan 2015 13:49:38 +0000 Subject: [PATCH] - memory.c:MyFree(): removed extraneous pointer test; renamed MyFree to xfree git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@5426 82007160-df01-0410-b94d-b575c5fd34c7 --- src/config-parser.y | 50 ++++++++++++++++++++++----------------------- src/dnsbl.c | 6 +++--- src/firedns.c | 8 ++++---- src/irc.c | 14 ++++++------- src/list.c | 4 ++-- src/memory.c | 10 +++------ src/memory.h | 4 +--- src/negcache.c | 4 ++-- src/opercmd.c | 6 +++--- src/scan.c | 12 +++++------ 10 files changed, 56 insertions(+), 62 deletions(-) diff --git a/src/config-parser.y b/src/config-parser.y index 9a3af93..f05d69a 100644 --- a/src/config-parser.y +++ b/src/config-parser.y @@ -152,7 +152,7 @@ options_negcache_rebuild: NEGCACHE_REBUILD '=' timespec ';' options_pidfile: PIDFILE '=' STRING ';' { - MyFree(OptionsItem->pidfile); + xfree(OptionsItem->pidfile); OptionsItem->pidfile = xstrdup($3); }; @@ -163,7 +163,7 @@ options_dns_fdlimit: DNS_FDLIMIT '=' NUMBER ';' options_scanlog: SCANLOG '=' STRING ';' { - MyFree(OptionsItem->scanlog); + xfree(OptionsItem->scanlog); OptionsItem->scanlog = xstrdup($3); }; @@ -195,43 +195,43 @@ irc_item: irc_away | irc_away: AWAY '=' STRING ';' { - MyFree(IRCItem->away); + xfree(IRCItem->away); IRCItem->away = xstrdup($3); }; irc_kline: KLINE '=' STRING ';' { - MyFree(IRCItem->kline); + xfree(IRCItem->kline); IRCItem->kline = xstrdup($3); }; irc_mode: MODE '=' STRING ';' { - MyFree(IRCItem->mode); + xfree(IRCItem->mode); IRCItem->mode = xstrdup($3); }; irc_nick: NICK '=' STRING ';' { - MyFree(IRCItem->nick); + xfree(IRCItem->nick); IRCItem->nick = xstrdup($3); }; irc_nickserv: NICKSERV '=' STRING ';' { - MyFree(IRCItem->nickserv); + xfree(IRCItem->nickserv); IRCItem->nickserv = xstrdup($3); }; irc_oper: OPER '=' STRING ';' { - MyFree(IRCItem->oper); + xfree(IRCItem->oper); IRCItem->oper = xstrdup($3); }; irc_password: PASSWORD '=' STRING ';' { - MyFree(IRCItem->password); + xfree(IRCItem->password); IRCItem->password = xstrdup($3); }; @@ -263,31 +263,31 @@ irc_readtimeout: READTIMEOUT '=' timespec ';' irc_realname: REALNAME '=' STRING ';' { - MyFree(IRCItem->realname); + xfree(IRCItem->realname); IRCItem->realname = xstrdup($3); }; irc_server: SERVER '=' STRING ';' { - MyFree(IRCItem->server); + xfree(IRCItem->server); IRCItem->server = xstrdup($3); }; irc_username: USERNAME '=' STRING ';' { - MyFree(IRCItem->username); + xfree(IRCItem->username); IRCItem->username = xstrdup($3); }; irc_vhost: VHOST '=' STRING ';' { - MyFree(IRCItem->vhost); + xfree(IRCItem->vhost); IRCItem->vhost = xstrdup($3); }; irc_connregex: CONNREGEX '=' STRING ';' { - MyFree(IRCItem->connregex); + xfree(IRCItem->connregex); IRCItem->connregex = xstrdup($3); }; @@ -323,7 +323,7 @@ channel_name: NAME '=' STRING ';' { struct ChannelConf *item = tmp; - MyFree(item->name); + xfree(item->name); item->name = xstrdup($3); }; @@ -331,7 +331,7 @@ channel_key: KEY '=' STRING ';' { struct ChannelConf *item = tmp; - MyFree(item->key); + xfree(item->key); item->key = xstrdup($3); }; @@ -339,7 +339,7 @@ channel_invite: INVITE '=' STRING ';' { struct ChannelConf *item = tmp; - MyFree(item->invite); + xfree(item->invite); item->invite = xstrdup($3); }; @@ -454,21 +454,21 @@ scanner_item: scanner_name | scanner_name: NAME '=' STRING ';' { struct ScannerConf *item = tmp; - MyFree(item->name); + xfree(item->name); item->name = xstrdup($3); }; scanner_vhost: VHOST '=' STRING ';' { struct ScannerConf *item = tmp; - MyFree(item->vhost); + xfree(item->vhost); item->vhost = xstrdup($3); }; scanner_target_ip: TARGET_IP '=' STRING ';' { struct ScannerConf *item = tmp; - MyFree(item->target_ip); + xfree(item->target_ip); item->target_ip = xstrdup($3); }; @@ -544,19 +544,19 @@ opm_item: opm_dnsbl_from | opm_dnsbl_from: DNSBL_FROM '=' STRING ';' { - MyFree(OpmItem->dnsbl_from); + xfree(OpmItem->dnsbl_from); OpmItem->dnsbl_from = xstrdup($3); }; opm_dnsbl_to: DNSBL_TO '=' STRING ';' { - MyFree(OpmItem->dnsbl_to); + xfree(OpmItem->dnsbl_to); OpmItem->dnsbl_to = xstrdup($3); }; opm_sendmail: SENDMAIL '=' STRING ';' { - MyFree(OpmItem->sendmail); + xfree(OpmItem->sendmail); OpmItem->sendmail = xstrdup($3); }; @@ -595,14 +595,14 @@ blacklist_item: blacklist_name | blacklist_name: NAME '=' STRING ';' { struct BlacklistConf *item = tmp; - MyFree(item->name); + xfree(item->name); item->name = xstrdup($3); }; blacklist_kline: KLINE '=' STRING ';' { struct BlacklistConf *item = tmp; - MyFree(item->kline); + xfree(item->kline); item->kline = xstrdup($3); }; diff --git a/src/dnsbl.c b/src/dnsbl.c index 261dba2..9cf966f 100644 --- a/src/dnsbl.c +++ b/src/dnsbl.c @@ -90,7 +90,7 @@ dnsbl_add(struct scan_struct *ss) if (res == -1 && firedns_errno != FDNS_ERR_FDLIMIT) { log_printf("DNSBL -> Error sending dns lookup for '%s': %s", lookup, firedns_strerror(firedns_errno)); - MyFree(ds); + xfree(ds); } else ++ss->scans; /* Increase scan count - one for each blacklist */ @@ -201,7 +201,7 @@ dnsbl_result(struct firedns_result *res) --ds->ss->scans; /* We are done with ss here */ scan_checkfinished(ds->ss); /* This could free ss, don't use ss after this point */ - MyFree(ds); /* No longer need our information */ + xfree(ds); /* No longer need our information */ return; } @@ -221,7 +221,7 @@ dnsbl_result(struct firedns_result *res) /* Check if ss has any remaining scans */ --ds->ss->scans; /* We are done with ss here */ scan_checkfinished(ds->ss); /* This could free ss, don't use ss after this point */ - MyFree(ds); /* Finished with dnsbl_scan too */ + xfree(ds); /* Finished with dnsbl_scan too */ } void diff --git a/src/firedns.c b/src/firedns.c index ded6d70..fdb48b7 100644 --- a/src/firedns.c +++ b/src/firedns.c @@ -325,7 +325,7 @@ firedns_getip(int type, const char * const name, void *info) /* Don't add to queue if there is no info */ if (info == NULL) - MyFree(s); + xfree(s); else { node = node_create(s); @@ -339,7 +339,7 @@ firedns_getip(int type, const char * const name, void *info) if (fd == -1) { - MyFree(s); + xfree(s); return -1; } @@ -754,7 +754,7 @@ cleanup: node_free(node); close(c->fd); firedns_fdinuse--; - MyFree(c); + xfree(c); return &result; } @@ -801,7 +801,7 @@ firedns_cycle(void) close(p->fd); firedns_fdinuse--; - MyFree(p); + xfree(p); firedns_errno = FDNS_ERR_TIMEOUT; diff --git a/src/irc.c b/src/irc.c index c2171ec..198689a 100644 --- a/src/irc.c +++ b/src/irc.c @@ -618,7 +618,7 @@ userinfo_create(char *source) if (nick == NULL || username == NULL || hostname == NULL) { - MyFree(tmp); + xfree(tmp); return NULL; } @@ -627,7 +627,7 @@ userinfo_create(char *source) ret->irc_username = xstrdup(username); ret->irc_hostname = xstrdup(hostname); - MyFree(tmp); + xfree(tmp); return ret; }; @@ -647,10 +647,10 @@ userinfo_free(struct UserInfo *source_p) if (source_p == NULL) return; - MyFree(source_p->irc_nick); - MyFree(source_p->irc_username); - MyFree(source_p->irc_hostname); - MyFree(source_p); + xfree(source_p->irc_nick); + xfree(source_p->irc_username); + xfree(source_p->irc_hostname); + xfree(source_p); } /* m_perform @@ -860,7 +860,7 @@ m_notice(char *parv[], unsigned int parc, const char *msg, const struct UserInfo log_printf("IRC REGEX -> Error when compiling regular expression"); log_printf("IRC REGEX -> %s", errmsg); - MyFree(preg); + xfree(preg); preg = NULL; return; } diff --git a/src/list.c b/src/list.c index 4435c0a..3573758 100644 --- a/src/list.c +++ b/src/list.c @@ -103,10 +103,10 @@ node_t *list_remove(list_t *list, node_t *node) void list_free(list_t *list) { - MyFree(list); + xfree(list); } void node_free(node_t *node) { - MyFree(node); + xfree(node); } diff --git a/src/memory.c b/src/memory.c index 20e5bd1..3d6f73d 100644 --- a/src/memory.c +++ b/src/memory.c @@ -47,7 +47,7 @@ void *xcalloc(size_t bytes) -/* MyFree +/* xfree * * Free memory allocated with xcalloc * @@ -58,13 +58,9 @@ void *xcalloc(size_t bytes) * None */ -void _MyFree(void **var) +void xfree(void *ptr) { - assert(var != NULL); - - if(*var != NULL) - free(*var); - *var = NULL; + free(ptr); } void * diff --git a/src/memory.h b/src/memory.h index 035a344..797efa3 100644 --- a/src/memory.h +++ b/src/memory.h @@ -21,10 +21,8 @@ #ifndef MALLOC_H #define MALLOC_H -#define MyFree(X) _MyFree((void **) &X) - extern void *xcalloc(size_t bytes); -extern void _MyFree(void **var); +extern void xfree(void *); extern void *xstrdup(const char *); #endif /* MALLOC_H */ diff --git a/src/negcache.c b/src/negcache.c index 6763a9e..a0b2031 100644 --- a/src/negcache.c +++ b/src/negcache.c @@ -267,7 +267,7 @@ static void nc_rebuild(struct cnode *old_head, struct cnode *new_head, } /* Safe to free() this node now. */ - MyFree(n); + xfree(n); } /* @@ -283,6 +283,6 @@ void negcache_rebuild(void) nc_init(&new_head); nc_rebuild(nc_head, new_head, NULL, now); - MyFree(nc_head); + xfree(nc_head); nc_head = new_head; } diff --git a/src/opercmd.c b/src/opercmd.c index 9b6e5cd..103be05 100644 --- a/src/opercmd.c +++ b/src/opercmd.c @@ -232,10 +232,10 @@ static void command_free(struct Command *command) { if (command->param) - MyFree(command->param); + xfree(command->param); - MyFree(command->irc_nick); - MyFree(command); + xfree(command->irc_nick); + xfree(command); } /* command_userhost diff --git a/src/scan.c b/src/scan.c index d0719f6..b9a7273 100644 --- a/src/scan.c +++ b/src/scan.c @@ -451,14 +451,14 @@ scan_free(struct scan_struct *ss) if (ss == NULL) return; - MyFree(ss->irc_nick); - MyFree(ss->irc_username); - MyFree(ss->irc_hostname); - MyFree(ss->ip); - MyFree(ss->proof); + xfree(ss->irc_nick); + xfree(ss->irc_username); + xfree(ss->irc_hostname); + xfree(ss->ip); + xfree(ss->proof); opm_remote_free(ss->remote); - MyFree(ss); + xfree(ss); } /* scan_checkfinished -- 2.30.2