Browse Source

Update memory allocation routines. Step 1 of X.

pull/1/head
Bram Matthys 3 years ago
parent
commit
de87b439b7
No known key found for this signature in database
GPG Key ID: BF8116B163EAAE98
  1. 23
      include/common.h
  2. 68
      include/h.h
  3. 14
      src/api-channelmode.c
  4. 14
      src/api-clicap.c
  5. 12
      src/api-command.c
  6. 11
      src/api-efunctions.c
  7. 10
      src/api-event.c
  8. 4
      src/api-extban.c
  9. 10
      src/api-history-backend.c
  10. 10
      src/api-isupport.c
  11. 10
      src/api-messagetag.c
  12. 10
      src/api-moddata.c
  13. 14
      src/api-usermode.c
  14. 6
      src/auth.c
  15. 2
      src/bsd.c
  16. 36
      src/channel.c
  17. 7
      src/cloak.c
  18. 698
      src/conf.c
  19. 40
      src/conf_preprocessor.c
  20. 19
      src/crule.c
  21. 8
      src/debug.c
  22. 40
      src/dns.c
  23. 14
      src/extra.c
  24. 12
      src/hash.c
  25. 11
      src/ircd.c
  26. 61
      src/list.c
  27. 16
      src/match.c
  28. 12
      src/mempool.c
  29. 40
      src/misc.c
  30. 150
      src/modules.c
  31. 2
      src/modules/account-tag.c
  32. 8
      src/modules/antimixedutf8.c
  33. 10
      src/modules/antirandom.c
  34. 14
      src/modules/authprompt.c
  35. 4
      src/modules/away.c
  36. 40
      src/modules/blacklist.c
  37. 4
      src/modules/certfp.c
  38. 4
      src/modules/chanmodes/censor.c
  39. 24
      src/modules/chanmodes/floodprot.c
  40. 6
      src/modules/chanmodes/history.c
  41. 6
      src/modules/chanmodes/link.c
  42. 33
      src/modules/channeldb.c
  43. 10
      src/modules/charsys.c
  44. 2
      src/modules/chghost.c
  45. 12
      src/modules/cloak.c
  46. 6
      src/modules/connthrottle.c
  47. 16
      src/modules/hideserver.c
  48. 16
      src/modules/history_backend_mem.c
  49. 6
      src/modules/jointhrottle.c
  50. 10
      src/modules/jumpserver.c
  51. 8
      src/modules/list.c
  52. 4
      src/modules/mdex.c
  53. 6
      src/modules/message-ids.c
  54. 2
      src/modules/message-tags.c
  55. 4
      src/modules/mode.c
  56. 10
      src/modules/nick.c
  57. 2
      src/modules/oper.c
  58. 2
      src/modules/pass.c
  59. 4
      src/modules/protoctl.c
  60. 12
      src/modules/reputation.c
  61. 14
      src/modules/require-module.c
  62. 8
      src/modules/restrict-commands.c
  63. 6
      src/modules/sasl.c
  64. 2
      src/modules/server-time.c
  65. 2
      src/modules/server.c
  66. 2
      src/modules/sethost.c
  67. 20
      src/modules/sinfo.c
  68. 12
      src/modules/sjoin.c
  69. 39
      src/modules/staff.c
  70. 4
      src/modules/svsmode.c
  71. 14
      src/modules/svsnline.c
  72. 98
      src/modules/tkl.c
  73. 29
      src/modules/tkldb.c
  74. 4
      src/modules/tls_antidos.c
  75. 8
      src/modules/topic.c
  76. 4
      src/modules/usermodes/censor.c
  77. 2
      src/modules/vhost.c
  78. 6
      src/modules/webirc.c
  79. 10
      src/modules/webredir.c
  80. 20
      src/modules/websocket.c
  81. 2
      src/modules/who_old.c
  82. 30
      src/operclass.c
  83. 2
      src/packet.c
  84. 4
      src/scache.c
  85. 34
      src/serv.c
  86. 52
      src/support.c
  87. 8
      src/tls.c
  88. 26
      src/updconf.c
  89. 16
      src/url.c
  90. 10
      src/user.c
  91. 10
      src/whowas.c
  92. 6
      src/windows/editor.c
  93. 16
      src/windows/gui.c
  94. 16
      src/windows/rtf.c
  95. 2
      src/windows/windebug.c

23
include/common.h

@ -163,29 +163,6 @@ extern MODVAR unsigned char char_atribs[];
#define ispunct(c) (!(char_atribs[(u_char)(c)]&(CNTRL|ALPHA|DIGIT)))
#define iswseperator(c) (!isalnum(c) && !((u_char)c >= 128))
#ifndef MALLOCD
#define MyFree free
#define MyMalloc malloc
#define MyRealloc realloc
#else
#define MyFree(x) do {debug(DEBUG_MALLOC, "%s:%i: free %02x", __FILE__, __LINE__, x); free(x); } while(0)
#define MyMalloc(x) StsMalloc(x, __FILE__, __LINE__)
#define MyRealloc realloc
static char *StsMalloc(size_t size, char *file, long line)
{
void *x;
x = malloc(size);
debug(DEBUG_MALLOC, "%s:%i: malloc %02x", file, line, x);
return x;
}
#endif
#define safestrdup(x,y) do { if (x) MyFree(x); if (!(y)) x = NULL; else x = strdup(y); } while(0)
#define safestrldup(x,y,sz) do { if (x) MyFree(x); if (!y) x = NULL; else x = strldup(y,sz); } while(0)
#define safefree(x) do { if (x) MyFree(x); x = NULL; } while(0)
/*
* Protocol support text. DO NO CHANGE THIS unless you know what
* you are doing.

68
include/h.h

@ -241,7 +241,7 @@ extern void set_channel_mlock(Client *, Client *, Channel *, const char *, int);
extern void restart(char *);
extern void server_reboot(char *);
extern void terminate(), write_pidfile();
extern void *MyMallocEx(size_t size);
extern void *safe_alloc(size_t size);
extern int send_queued(Client *);
extern void sendto_connectnotice(Client *sptr, int disconnect, char *comment);
extern void sendto_serv_butone_nickcmd(Client *one, Client *sptr, char *umodes);
@ -470,7 +470,6 @@ extern char *oflagstr(long oflag);
extern int rehash(Client *cptr, Client *sptr, int sig);
extern int match_simple(const char *mask, const char *name);
extern int match_esc(const char *mask, const char *name);
extern void outofmemory(void);
extern int add_listener(ConfigItem_listen *conf);
extern void link_cleanup(ConfigItem_link *link_ptr);
extern void listen_cleanup();
@ -494,7 +493,70 @@ extern time_t rfc2time(char *s);
extern char *rfctime(time_t t, char *buf);
extern int strnatcmp(char const *a, char const *b);
extern int strnatcasecmp(char const *a, char const *b);
extern void *MyMallocEx(size_t size);
extern void outofmemory(size_t bytes);
/** Memory allocation and deallocation functions and macros that should be used in UnrealIRCd.
* Use these instead of malloc/calloc/free.
* @defgroup MemoryRoutines Memory allocation and deallocation
* @{
*/
extern void *safe_alloc(size_t size);
/** Free previously allocate memory pointer.
* This also sets the pointer to NULL, since that would otherwise be common to forget.
*/
#define safe_free(x) do { if (x) free(x); x = NULL; } while(0)
/** Free previously allocated memory pointer.
* Raw version which does not touch the pointer itself. You most likely don't
* need this, as it's only used in 1 place in UnrealIRCd.
*/
#define safe_free_raw(x) free(x)
/** Free previous memory (if any) and then save a duplicate of the specified string.
* @param dst The current pointer and the pointer where a new copy of the string will be stored.
* @param str The string you want to copy
*/
#define safe_strdup(dst,str) do { if (dst) free(dst); if (!(str)) dst = NULL; else dst = our_strdup(str); } while(0)
/** Return a copy of the string. Do not free any existing memory.
* @param str The string to duplicate
* @returns A pointer to the new copy.
* @notes
* Generally you need to use safe_strdup() instead(!). But when clearly initializing
* a variable that does not have a previous value, then raw_strdup() usage is fine, eg:
* int somefunc()
* {
* char *somevar = raw_strdup("IRC");
* And, similarly if you want to return a duplicate (there is no destination variable):
* return raw_strdup(something);
*/
#define raw_strdup(str) strdup(str)
/** Free previous memory (if any) and then save a duplicate of the specified string with a length limit.
* @param dst The current pointer and the pointer where a new copy of the string will be stored.
* @param str The string you want to copy
* @param sz Length limit including the NUL byte, usually sizeof(dst)
*/
#define safe_strldup(dst,str,sz) do { if (dst) free(dst); if (!str) dst = NULL; else dst = our_strldup(str,sz); } while(0)
/** Return a duplicate of the specified string with a length limit. Do not free any existing memory.
* @param str The string you want to copy
* @param sz Length limit including the NUL byte, usually sizeof(dst)
* @returns A pointer to the new copy.
* @notes
* Generally you need to use safe_strldup() instead(!). But when clearly initializing
* a variable that does not have a previous value, then raw_strldup() usage is fine, eg:
* int somefunc(char *str)
* {
* char *somevar = raw_strldup(str, 16);
* And, similarly if you want to return a duplicate (there is no destination variable):
* return raw_strldup(something);
*/
#define raw_strldup(str, max) our_strldup(str, max)
/** @} */
extern char *our_strdup(const char *str);
extern char *our_strldup(const char *str, size_t max);
extern MODFUNC char *tls_get_cipher(SSL *ssl);
extern TLSOptions *get_tls_options_for_client(Client *acptr);
extern int outdated_tls_client(Client *acptr);

14
src/api-channelmode.c

@ -102,13 +102,13 @@ void extcmodes_check_for_changes(void)
make_extcmodestr();
snprintf(chanmodes, sizeof(chanmodes), "%s%s", CHPAR1, EXPAR1);
safestrdup(me.serv->features.chanmodes[0], chanmodes);
safe_strdup(me.serv->features.chanmodes[0], chanmodes);
snprintf(chanmodes, sizeof(chanmodes), "%s%s", CHPAR2, EXPAR2);
safestrdup(me.serv->features.chanmodes[1], chanmodes);
safe_strdup(me.serv->features.chanmodes[1], chanmodes);
snprintf(chanmodes, sizeof(chanmodes), "%s%s", CHPAR3, EXPAR3);
safestrdup(me.serv->features.chanmodes[2], chanmodes);
safe_strdup(me.serv->features.chanmodes[2], chanmodes);
snprintf(chanmodes, sizeof(chanmodes), "%s%s", CHPAR4, EXPAR4);
safestrdup(me.serv->features.chanmodes[3], chanmodes);
safe_strdup(me.serv->features.chanmodes[3], chanmodes);
ircsnprintf(chanmodes, sizeof(chanmodes), "%s,%s,%s,%s",
me.serv->features.chanmodes[0],
@ -142,7 +142,7 @@ void extcmode_init(void)
{
Cmode_t val = 1;
int i;
Channelmode_Table = MyMallocEx(sizeof(Cmode) * EXTCMODETABLESZ);
Channelmode_Table = safe_alloc(sizeof(Cmode) * EXTCMODETABLESZ);
for (i = 0; i < EXTCMODETABLESZ; i++)
{
Channelmode_Table[i].mode = val;
@ -256,7 +256,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode)
if (module)
{
ModuleObject *cmodeobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *cmodeobj = safe_alloc(sizeof(ModuleObject));
cmodeobj->object.cmode = &Channelmode_Table[i];
cmodeobj->type = MOBJ_CMODE;
AddListItem(cmodeobj, module->objects);
@ -342,7 +342,7 @@ void CmodeDel(Cmode *cmode)
for (cmodeobj = cmode->owner->objects; cmodeobj; cmodeobj = cmodeobj->next) {
if (cmodeobj->type == MOBJ_CMODE && cmodeobj->object.cmode == cmode) {
DelListItem(cmodeobj, cmode->owner->objects);
MyFree(cmodeobj);
safe_free(cmodeobj);
break;
}
}

14
src/api-clicap.c

@ -169,7 +169,7 @@ ClientCapability *ClientCapabilityAdd(Module *module, ClientCapabilityInfo *clic
}
}
/* New client capability */
clicap = MyMallocEx(sizeof(ClientCapability));
clicap = safe_alloc(sizeof(ClientCapability));
clicap->name = strdup(clicap_request->name);
clicap->cap = v;
}
@ -190,7 +190,7 @@ ClientCapability *ClientCapabilityAdd(Module *module, ClientCapabilityInfo *clic
if (module)
{
ModuleObject *clicapobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *clicapobj = safe_alloc(sizeof(ModuleObject));
clicapobj->object.clicap = clicap;
clicapobj->type = MOBJ_CLICAP;
AddListItem(clicapobj, module->objects);
@ -221,8 +221,8 @@ void unload_clicap_commit(ClientCapability *clicap)
/* Destroy the capability */
DelListItem(clicap, clicaps);
safefree(clicap->name);
MyFree(clicap);
safe_free(clicap->name);
safe_free(clicap);
}
/**
* Removes the specified clicap token.
@ -237,7 +237,7 @@ void ClientCapabilityDel(ClientCapability *clicap)
for (mobj = clicap->owner->objects; mobj; mobj = mobj->next) {
if (mobj->type == MOBJ_CLICAP && mobj->object.clicap == clicap) {
DelListItem(mobj, clicap->owner->objects);
MyFree(mobj);
safe_free(mobj);
break;
}
}
@ -281,7 +281,7 @@ void clicap_pre_rehash(void)
ircd_log(LOG_ERROR, "More than %d caps loaded - what???", MAXCLICAPS);
break;
}
old_caps[i] = strdup(clicap->name);
safe_strdup(old_caps[i], clicap->name);
old_caps_proto[i] = clicap->cap;
i++;
}
@ -368,5 +368,5 @@ void clicap_post_rehash(void)
/* Now free the old caps. */
for (i = 0; old_caps[i]; i++)
safefree(old_caps[i]);
safe_free(old_caps[i]);
}

12
src/api-command.c

@ -60,8 +60,8 @@ Command *CommandAddInternal(Module *module, char *cmd, CmdFunc func, AliasCmdFun
if (module)
{
ModuleObject *cmdobj = MyMallocEx(sizeof(ModuleObject));
command = MyMallocEx(sizeof(Command));
ModuleObject *cmdobj = safe_alloc(sizeof(ModuleObject));
command = safe_alloc(sizeof(Command));
command->cmd = c;
command->cmd->owner = module;
command->cmd->friend = NULL;
@ -115,7 +115,7 @@ void CommandDelX(Command *command, RealCommand *cmd)
if (cmdobj->type == MOBJ_COMMAND && cmdobj->object.command == command)
{
DelListItem(cmdobj,cmd->owner->objects);
MyFree(cmdobj);
safe_free(cmdobj);
break;
}
}
@ -125,10 +125,10 @@ void CommandDelX(Command *command, RealCommand *cmd)
ovrnext = ovr->next;
CommandOverrideDel(ovr);
}
MyFree(cmd->cmd);
MyFree(cmd);
safe_free(cmd->cmd);
safe_free(cmd);
if (command)
MyFree(command);
safe_free(command);
}
void CommandDel(Command *command)

11
src/api-efunctions.c

@ -129,7 +129,7 @@ Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(),
return NULL;
}
p = MyMallocEx(sizeof(Efunction));
p = safe_alloc(sizeof(Efunction));
if (func)
p->func.intfunc = func;
if (vfunc)
@ -143,7 +143,7 @@ Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(),
AddListItem(p, Efunctions[eftype]);
if (module)
{
ModuleObject *cbobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *cbobj = safe_alloc(sizeof(ModuleObject));
cbobj->object.efunction = p;
cbobj->type = MOBJ_EFUNCTION;
AddListItem(cbobj, module->objects);
@ -172,12 +172,12 @@ Efunction *EfunctionDel(Efunction *cb)
if ((cbobj->type == MOBJ_EFUNCTION) && (cbobj->object.efunction == p))
{
DelListItem(cbobj, cb->owner->objects);
MyFree(cbobj);
safe_free(cbobj);
break;
}
}
}
MyFree(p);
safe_free(p);
return q;
}
}
@ -273,13 +273,14 @@ void efunctions_switchover(void)
void efunc_init_function_(EfunctionType what, char *name, void *func, void *default_func)
{
efunction_table[what].name = strdup(name);
safe_strdup(efunction_table[what].name, name);
efunction_table[what].funcptr = func;
efunction_table[what].deffunc = default_func;
}
void efunctions_init(void)
{
memset(&efunction_table, 0, sizeof(efunction_table));
efunc_init_function(EFUNC_DO_JOIN, do_join, NULL);
efunc_init_function(EFUNC_JOIN_CHANNEL, join_channel, NULL);
efunc_init_function(EFUNC_CAN_JOIN, can_join, NULL);

10
src/api-event.c

@ -39,7 +39,7 @@ Event *EventAdd(Module *module, char *name, long every, long howmany,
module->errorcode = MODERR_INVALID;
return NULL;
}
newevent = MyMallocEx(sizeof(Event));
newevent = safe_alloc(sizeof(Event));
newevent->name = strdup(name);
newevent->howmany = howmany;
newevent->every = every;
@ -50,7 +50,7 @@ Event *EventAdd(Module *module, char *name, long every, long howmany,
AddListItem(newevent,events);
if (module)
{
ModuleObject *eventobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *eventobj = safe_alloc(sizeof(ModuleObject));
eventobj->object.event = newevent;
eventobj->type = MOBJ_EVENT;
AddListItem(eventobj, module->objects);
@ -74,7 +74,7 @@ Event *EventDel(Event *event)
if (p == event)
{
q = p->next;
MyFree(p->name);
safe_free(p->name);
DelListItem(p, events);
if (p->owner)
{
@ -84,12 +84,12 @@ Event *EventDel(Event *event)
if (eventobjs->type == MOBJ_EVENT && eventobjs->object.event == p)
{
DelListItem(eventobjs, p->owner->objects);
MyFree(eventobjs);
safe_free(eventobjs);
break;
}
}
}
MyFree(p);
safe_free(p);
return q;
}
}

4
src/api-extban.c

@ -80,7 +80,7 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req)
ExtBan_Table[slot].options = req.options;
if (module)
{
ModuleObject *banobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *banobj = safe_alloc(sizeof(ModuleObject));
banobj->object.extban = &ExtBan_Table[slot];
banobj->type = MOBJ_EXTBAN;
AddListItem(banobj, module->objects);
@ -103,7 +103,7 @@ void ExtbanDel(Extban *eb)
if (banobj->type == MOBJ_EXTBAN && banobj->object.extban == eb)
{
DelListItem(banobj, eb->owner->objects);
MyFree(banobj);
safe_free(banobj);
break;
}
}

10
src/api-history-backend.c

@ -82,7 +82,7 @@ HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mreq)
}
} else {
/* New history backend */
m = MyMallocEx(sizeof(HistoryBackend));
m = safe_alloc(sizeof(HistoryBackend));
m->name = strdup(mreq->name);
}
@ -98,7 +98,7 @@ HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mreq)
if (module)
{
ModuleObject *mobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *mobj = safe_alloc(sizeof(ModuleObject));
mobj->type = MOBJ_HISTORY_BACKEND;
mobj->object.history_backend = m;
AddListItem(mobj, module->objects);
@ -112,8 +112,8 @@ void unload_history_backend_commit(HistoryBackend *m)
{
/* Destroy the object */
DelListItem(m, historybackends);
safefree(m->name);
MyFree(m);
safe_free(m->name);
safe_free(m);
}
/**
@ -130,7 +130,7 @@ void HistoryBackendDel(HistoryBackend *m)
if (mobj->type == MOBJ_HISTORY_BACKEND && mobj->object.history_backend == m)
{
DelListItem(mobj, m->owner->objects);
MyFree(mobj);
safe_free(mobj);
break;
}
}

10
src/api-isupport.c

@ -217,7 +217,7 @@ ISupport *ISupportAdd(Module *module, const char *token, const char *value)
}
}
isupport = MyMallocEx(sizeof(ISupport));
isupport = safe_alloc(sizeof(ISupport));
isupport->owner = module;
isupport->token = strdup(token);
if (value)
@ -226,7 +226,7 @@ ISupport *ISupportAdd(Module *module, const char *token, const char *value)
make_isupportstrings();
if (module)
{
ModuleObject *isupportobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *isupportobj = safe_alloc(sizeof(ModuleObject));
isupportobj->object.isupport = isupport;
isupportobj->type = MOBJ_ISUPPORT;
AddListItem(isupportobj, module->objects);
@ -265,10 +265,10 @@ void make_isupportstrings(void)
/* Free any previous strings */
for (i = 0; ISupportStrings[i]; i++)
safefree(ISupportStrings[i]);
safe_free(ISupportStrings[i]);
i = 0;
ISupportStrings[i] = MyMallocEx(bufsize+1);
ISupportStrings[i] = safe_alloc(bufsize+1);
for (isupport = ISupports; isupport; isupport = isupport->next)
{
@ -281,7 +281,7 @@ void make_isupportstrings(void)
if ((strlen(ISupportStrings[i]) + strlen(tmp) + 1 >= ISUPPORTLEN) || (tokcnt == 13))
{
/* No room or max tokens reached: start a new buffer */
ISupportStrings[++i] = MyMallocEx(bufsize+1);
ISupportStrings[++i] = safe_alloc(bufsize+1);
tokcnt = 1;
if (i == MAXISUPPORTLINES)
abort(); /* should never happen anyway */

10
src/api-messagetag.c

@ -88,7 +88,7 @@ MessageTagHandler *MessageTagHandlerAdd(Module *module, MessageTagHandlerInfo *m
}
} else {
/* New message tag handler */
m = MyMallocEx(sizeof(MessageTagHandler));
m = safe_alloc(sizeof(MessageTagHandler));
m->name = strdup(mreq->name);
}
/* Add or update the following fields: */
@ -105,7 +105,7 @@ MessageTagHandler *MessageTagHandlerAdd(Module *module, MessageTagHandlerInfo *m
if (module)
{
ModuleObject *mobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *mobj = safe_alloc(sizeof(ModuleObject));
mobj->type = MOBJ_MTAG;
mobj->object.mtag = m;
AddListItem(mobj, module->objects);
@ -127,8 +127,8 @@ void unload_mtag_handler_commit(MessageTagHandler *m)
/* Destroy the object */
DelListItem(m, mtaghandlers);
safefree(m->name);
MyFree(m);
safe_free(m->name);
safe_free(m);
}
/**
@ -145,7 +145,7 @@ void MessageTagHandlerDel(MessageTagHandler *m)
if (mobj->type == MOBJ_MTAG && mobj->object.mtag == m)
{
DelListItem(mobj, m->owner->objects);
MyFree(mobj);
safe_free(mobj);
break;
}
}

10
src/api-moddata.c

@ -70,7 +70,7 @@ ModDataInfo *ModDataAdd(Module *module, ModDataInfo req)
}
new_struct = 1;
m = MyMallocEx(sizeof(ModDataInfo));
m = safe_alloc(sizeof(ModDataInfo));
m->name = strdup(req.name);
m->slot = slotav;
m->type = req.type;
@ -86,7 +86,7 @@ moddataadd_isok:
if (module)
{
ModuleObject *mobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *mobj = safe_alloc(sizeof(ModuleObject));
mobj->object.moddata = m;
mobj->type = MOBJ_MODDATA;
AddListItem(mobj, module->objects);
@ -227,8 +227,8 @@ void unload_moddata_commit(ModDataInfo *md)
}
DelListItem(md, MDInfo);
MyFree(md->name);
MyFree(md);
safe_free(md->name);
safe_free(md);
}
void ModDataDel(ModDataInfo *md)
@ -242,7 +242,7 @@ void ModDataDel(ModDataInfo *md)
if ((mdobj->type == MOBJ_MODDATA) && (mdobj->object.moddata == md))
{
DelListItem(mdobj, md->owner->objects);
MyFree(mdobj);
safe_free(mdobj);
break;
}
}

14
src/api-usermode.c

@ -65,7 +65,7 @@ void umode_init(void)
{
long val = 1;
int i;
Usermode_Table = MyMallocEx(sizeof(Umode) * UMODETABLESZ);
Usermode_Table = safe_alloc(sizeof(Umode) * UMODETABLESZ);
for (i = 0; i < UMODETABLESZ; i++)
{
Usermode_Table[i].mode = val;
@ -73,7 +73,7 @@ void umode_init(void)
}
Usermode_highest = 0;
Snomask_Table = MyMallocEx(sizeof(Snomask) * UMODETABLESZ);
Snomask_Table = safe_alloc(sizeof(Snomask) * UMODETABLESZ);
val = 1;
for (i = 0; i < UMODETABLESZ; i++)
{
@ -129,7 +129,7 @@ static char previous_umodestring[256];
void umodes_check_for_changes(void)
{
make_umodestr();
safestrdup(me.serv->features.usermodes, umodestring);
safe_strdup(me.serv->features.usermodes, umodestring);
if (!*previous_umodestring)
{
@ -201,7 +201,7 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (*
Usermode_Table[i].owner = module;
if (module)
{
ModuleObject *umodeobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *umodeobj = safe_alloc(sizeof(ModuleObject));
umodeobj->object.umode = &(Usermode_Table[i]);
umodeobj->type = MOBJ_UMODE;
AddListItem(umodeobj, module->objects);
@ -247,7 +247,7 @@ void UmodeDel(Umode *umode)
for (umodeobj = umode->owner->objects; umodeobj; umodeobj = umodeobj->next) {
if (umodeobj->type == MOBJ_UMODE && umodeobj->object.umode == umode) {
DelListItem(umodeobj, umode->owner->objects);
MyFree(umodeobj);
safe_free(umodeobj);
break;
}
}
@ -296,7 +296,7 @@ Snomask *SnomaskAdd(Module *module, char ch, int (*allowed)(Client *sptr, int wh
Snomask_Table[i].owner = module;
if (module)
{
ModuleObject *snoobj = MyMallocEx(sizeof(ModuleObject));
ModuleObject *snoobj = safe_alloc(sizeof(ModuleObject));
snoobj->object.snomask = &(Snomask_Table[i]);
snoobj->type = MOBJ_SNOMASK;
AddListItem(snoobj, module->objects);
@ -340,7 +340,7 @@ void SnomaskDel(Snomask *sno)
for (snoobj = sno->owner->objects; snoobj; snoobj = snoobj->next) {
if (snoobj->type == MOBJ_SNOMASK && snoobj->object.snomask == sno) {
DelListItem(snoobj, sno->owner->objects);
MyFree(snoobj);
safe_free(snoobj);
break;
}
}

6
src/auth.c

@ -263,7 +263,7 @@ AuthConfig *AuthBlockToAuthConfig(ConfigEntry *ce)
if (type == AUTHTYPE_INVALID)
type = AUTHTYPE_PLAINTEXT;
as = MyMallocEx(sizeof(AuthConfig));
as = safe_alloc(sizeof(AuthConfig));
as->data = strdup(ce->ce_vardata);
as->type = type;
return as;
@ -274,8 +274,8 @@ void Auth_FreeAuthConfig(AuthConfig *as)
{
if (as)
{
safefree(as->data);
MyFree(as);
safe_free(as->data);
safe_free(as);
}
}

2
src/bsd.c

@ -1353,7 +1353,7 @@ int connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp)
if (!hp)
{
/* Remove "cache" */
safefree(aconf->connect_ip);
safe_free(aconf->connect_ip);
}
/*
* If we dont know the IP# for this host and itis a hostname and

36
src/channel.c

@ -137,7 +137,7 @@ static Member *make_member(void)
{
for (i = 1; i <= (4072/sizeof(Member)); ++i)
{
lp = MyMallocEx(sizeof(Member));
lp = safe_alloc(sizeof(Member));
lp->cptr = NULL;
lp->flags = 0;
lp->next = freemember;
@ -171,7 +171,7 @@ static Membership *make_membership(void)
{
for (i = 1; i <= (4072/sizeof(Membership)); i++)
{
m = MyMallocEx(sizeof(Membership));
m = safe_alloc(sizeof(Membership));
m->next = freemembership;
freemembership = m;
}
@ -313,8 +313,8 @@ int add_listmode_ex(Ban **list, Client *cptr, Channel *chptr, char *banid, char
}
/* Update/set if this ban is new or older than existing one */
safestrdup(ban->banstr, banid); /* cAsE may differ, use oldest version of it */
safestrdup(ban->who, setby);
safe_strdup(ban->banstr, banid); /* cAsE may differ, use oldest version of it */
safe_strdup(ban->who, setby);
ban->when = seton;
return 0;
}
@ -350,8 +350,8 @@ int del_listmode(Ban **list, Channel *chptr, char *banid)
{
tmp = *ban;
*ban = tmp->next;
MyFree(tmp->banstr);
MyFree(tmp->who);
safe_free(tmp->banstr);
safe_free(tmp->who);
free_ban(tmp);
return 0;
}
@ -908,7 +908,7 @@ Channel *get_channel(Client *cptr, char *chname, int flag)
return (chptr);
if (flag == CREATE)
{
chptr = MyMallocEx(sizeof(Channel) + len);
chptr = safe_alloc(sizeof(Channel) + len);
strlcpy(chptr->chname, chname, len + 1);
if (channel)
channel->prevch = chptr;
@ -1033,24 +1033,24 @@ int sub1_from_channel(Channel *chptr)
{
ban = chptr->banlist;
chptr->banlist = ban->next;
MyFree(ban->banstr);
MyFree(ban->who);
safe_free(ban->banstr);
safe_free(ban->who);
free_ban(ban);
}
while (chptr->exlist)
{
ban = chptr->exlist;
chptr->exlist = ban->next;
MyFree(ban->banstr);
MyFree(ban->who);
safe_free(ban->banstr);
safe_free(ban->who);
free_ban(ban);
}
while (chptr->invexlist)
{
ban = chptr->invexlist;
chptr->invexlist = ban->next;
MyFree(ban->banstr);
MyFree(ban->who);
safe_free(ban->banstr);
safe_free(ban->who);
free_ban(ban);
}
@ -1058,11 +1058,11 @@ int sub1_from_channel(Channel *chptr)
extcmode_free_paramlist(chptr->mode.extmodeparams);
if (chptr->mode_lock)
MyFree(chptr->mode_lock);
safe_free(chptr->mode_lock);
if (chptr->topic)
MyFree(chptr->topic);
safe_free(chptr->topic);
if (chptr->topic_nick)
MyFree(chptr->topic_nick);
safe_free(chptr->topic_nick);
if (chptr->prevch)
chptr->prevch->nextch = chptr->nextch;
else
@ -1071,7 +1071,7 @@ int sub1_from_channel(Channel *chptr)
chptr->nextch->prevch = chptr->prevch;
(void)del_from_channel_hash_table(chptr->chname, chptr);
ircstats.channels--;
MyFree(chptr);
safe_free(chptr);
return 1;
}
@ -1130,7 +1130,7 @@ void send_user_joins(Client *cptr, Client *user)
void set_channel_mlock(Client *cptr, Client *sptr, Channel *chptr, const char *newmlock, int propagate)
{
if (chptr->mode_lock)
MyFree(chptr->mode_lock);
safe_free(chptr->mode_lock);
chptr->mode_lock = (newmlock != NULL) ? strdup(newmlock) : NULL;
if (propagate)

7
src/cloak.c

@ -20,7 +20,7 @@
/* mode = 0, just use strlcpy, 1 = Realloc new and return new pointer */
char *make_virthost(Client *sptr, char *curr, char *new, int mode)
{
char host[256], *mask, *x, *p, *q;
char host[256], *mask, *p, *q;
if (!curr)
return NULL;
@ -44,7 +44,6 @@ char host[256], *mask, *x, *p, *q;
return NULL;
}
if (new)
MyFree(new);
x = strdup(mask);
return x;
safe_free(new);
return raw_strdup(mask);
}

698
src/conf.c

File diff suppressed because it is too large Load Diff

40
src/conf_preprocessor.c

@ -71,7 +71,7 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co
return PREPROCESSOR_ERROR;
}
*p = '\0';
cc = MyMallocEx(sizeof(ConditionalConfig));
cc = safe_alloc(sizeof(ConditionalConfig));
cc->condition = IF_MODULE;
cc->negative = negative;
cc->name = strdup(name);
@ -101,7 +101,7 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co
return PREPROCESSOR_ERROR;
}
*p = '\0';
cc = MyMallocEx(sizeof(ConditionalConfig));
cc = safe_alloc(sizeof(ConditionalConfig));
cc->condition = IF_DEFINED;
cc->negative = negative;
cc->name = strdup(name);
@ -165,7 +165,7 @@ int evaluate_preprocessor_if(char *statement, char *filename, int linenumber, Co
return PREPROCESSOR_ERROR;
}
*p = '\0';
cc = MyMallocEx(sizeof(ConditionalConfig));
cc = safe_alloc(sizeof(ConditionalConfig));
cc->condition = IF_VALUE;
cc->negative = negative;
cc->name = strdup(name);
@ -215,7 +215,7 @@ int evaluate_preprocessor_define(char *statement, char *filename, int linenumber
*p = '\0';
*name_terminator = '\0';
NameValueList *d = MyMallocEx(sizeof(NameValueList));
NameValueList *d = safe_alloc(sizeof(NameValueList));
d->name = strdup(name);
d->value = strdup(value);
AddListItem(d, config_defines);
@ -250,9 +250,9 @@ int parse_preprocessor_item(char *start, char *end, char *filename, int linenumb
*/
void preprocessor_cc_free_entry(ConditionalConfig *cc)
{
safefree(cc->name);
safefree(cc->opt);
MyFree(cc);
safe_free(cc->name);
safe_free(cc->opt);
safe_free(cc);
}
/** Free ConditionalConfig entries in a linked list that
@ -280,9 +280,9 @@ void preprocessor_cc_duplicate_list(ConditionalConfig *r, ConditionalConfig **ou
*out = NULL;
for (; r; r = r->next)
{
cc = MyMallocEx(sizeof(ConditionalConfig));
safestrdup(cc->name, r->name);
safestrdup(cc->opt, r->opt);
cc = safe_alloc(sizeof(ConditionalConfig));
safe_strdup(cc->name, r->name);
safe_strdup(cc->opt, r->opt);
cc->priority = r->priority;
cc->condition = r->condition;
cc->negative = r->negative;
@ -297,9 +297,9 @@ void preprocessor_cc_free_list(ConditionalConfig *cc)
for (; cc; cc = cc_next)
{
cc_next = cc->next;
safefree(cc->name);
safefree(cc->opt);
MyFree(cc);
safe_free(cc->name);
safe_free(cc->opt);
safe_free(cc);
}
}
@ -310,9 +310,9 @@ void free_config_entry(ConfigEntry *ce)
preprocessor_cc_free_list(ce->ce_cond);
/* free ConfigEntry */
safefree(ce->ce_varname);
safefree(ce->ce_vardata);
MyFree(ce);
safe_free(ce->ce_varname);
safe_free(ce->ce_vardata);
safe_free(ce);
}
NameValueList *find_config_define(const char *name)
@ -435,9 +435,9 @@ void free_config_defines(void)
for (e = config_defines; e; e = e_next)
{
e_next = e->next;
safefree(e->name);
safefree(e->value);
MyFree(e);
safe_free(e->name);
safe_free(e->value);
safe_free(e);
}
config_defines = NULL;
}
@ -505,5 +505,5 @@ void preprocessor_replace_defines(char **item)
break; /* no input buffer left */
}
*o = '\0';
safestrdup(*item, buf);
safe_strdup(*item, buf);
}

19
src/crule.c

@ -52,10 +52,9 @@ ID_Copyright("(C) Tony Vincell");
#endif
#if defined(CR_DEBUG) || defined(CR_CHKCONF)
#define MyMalloc malloc
#undef MyFree
#undef safe_free
#undef free
#define MyFree free
#define safe_free free
#endif
/* some constants and shared data types */
@ -386,7 +385,7 @@ int crule_parseorexpr(crule_treeptr *orrootp, int *next_tokp, char **ruleptr)
if ((errcode == CR_NOERR) && (*next_tokp == CR_OR))
{
orptr =
(crule_treeptr) MyMallocEx(sizeof(crule_treeelem));
(crule_treeptr) safe_alloc(sizeof(crule_treeelem));
#ifdef CR_DEBUG
(void)fprintf(stderr, "allocating or element at %ld\n", orptr);
#endif
@ -440,7 +439,7 @@ int crule_parseandexpr(crule_treeptr *androotp, int *next_tokp, char **ruleptr)
if ((errcode == CR_NOERR) && (*next_tokp == CR_AND))
{
andptr =
(crule_treeptr) MyMallocEx(sizeof(crule_treeelem));
(crule_treeptr) safe_alloc(sizeof(crule_treeelem));
#ifdef CR_DEBUG
(void)fprintf(stderr, "allocating and element at %ld\n", andptr);
#endif
@ -514,7 +513,7 @@ int crule_parseprimary(crule_treeptr *primrootp, int *next_tokp, char **ruleptr
break;
case CR_NOT:
*insertionp =
(crule_treeptr) MyMallocEx(sizeof(crule_treeelem));
(crule_treeptr) safe_alloc(sizeof(crule_treeelem));
#ifdef CR_DEBUG
(void)fprintf(stderr,
"allocating primary element at %ld\n",
@ -568,7 +567,7 @@ int crule_parsefunction(crule_treeptr *funcrootp, int *next_tokp, char **rulept
}
if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
return (errcode);
*funcrootp = (crule_treeptr) MyMallocEx(sizeof(crule_treeelem));
*funcrootp = (crule_treeptr) safe_alloc(sizeof(crule_treeelem));
#ifdef CR_DEBUG
(void)fprintf(stderr, "allocating function element at %ld\n",
*funcrootp);
@ -631,7 +630,7 @@ int crule_parsearglist(crule_treeptr argrootp, int *next_tokp, char **ruleptr)
#endif
if (*currarg)
{
argelemp = strdup(currarg);
safe_strdup(argelemp, currarg);
argrootp->arg[argrootp->numargs++] = (void *)argelemp;
}
if (*next_tokp != CR_COMMA)
@ -672,12 +671,12 @@ void crule_free(char **elem)
{
numargs = (*((crule_treeptr *) elem))->numargs;
for (arg = 0; arg < numargs; arg++)
MyFree((char *)(*((crule_treeptr *) elem))->arg[arg]);
safe_free_raw((char *)(*((crule_treeptr *) elem))->arg[arg]);
}
#ifdef CR_DEBUG
(void)fprintf(stderr, "freeing element at %ld\n", *elem);
#endif
MyFree(*elem);
safe_free(*elem);
*elem = NULL;
}

8
src/debug.c

@ -72,10 +72,10 @@ void flag_add(char ch)
if (extraflags)
{
char tmp[2] = { ch, 0 };
newextra = MyMallocEx(strlen(extraflags) + 2);
newextra = safe_alloc(strlen(extraflags) + 2);
strcpy(newextra, extraflags);
strcat(newextra, tmp);
MyFree(extraflags);
safe_free(extraflags);
extraflags = newextra;
}
else
@ -96,12 +96,12 @@ void flag_del(char ch)
for (newsz = 0, p = extraflags; *p; p++)
if (*p != ch)
newsz++;
newflags = MyMallocEx(newsz + 1);
newflags = safe_alloc(newsz + 1);
for (p = newflags, op = extraflags; (*op) && (newsz); newsz--, op++)
if (*op != ch)
*p++ = *op;
*p = '\0';
MyFree(extraflags);
safe_free(extraflags);
extraflags = newflags;
}

40
src/dns.c

@ -209,7 +209,7 @@ struct hostent *unrealdns_doclient(Client *cptr)
return unreal_create_hostent(cache_name, cptr->ip);
/* Create a request */
r = MyMallocEx(sizeof(DNSReq));
r = safe_alloc(sizeof(DNSReq));
r->cptr = cptr;
r->ipv6 = IsIPV6(cptr);
unrealdns_addreqtolist(r);
@ -238,7 +238,7 @@ void unrealdns_gethostbyname_link(char *name, ConfigItem_link *conf, int ipv4_on
DNSReq *r;
/* Create a request */
r = MyMallocEx(sizeof(DNSReq));
r = safe_alloc(sizeof(DNSReq));
r->linkblock = conf;
r->name = strdup(name);
if (!DISABLE_IPV6 && !ipv4_only)
@ -274,7 +274,7 @@ char ipv6 = r->ipv6;
}
/* Good, we got a valid response, now prepare for name -> ip */
newr = MyMallocEx(sizeof(DNSReq));
newr = safe_alloc(sizeof(DNSReq));
newr->cptr = acptr;
newr->ipv6 = ipv6;
newr->name = strdup(he->h_name);
@ -466,7 +466,7 @@ static void unrealdns_addtocache(char *name, char *ip)
}
/* Create record */
c = MyMallocEx(sizeof(DNSCache));
c = safe_alloc(sizeof(DNSCache));
c->name = strdup(name);
c->ip = strdup(ip);
c->expires = TStime() + DNSCACHE_TTL;
@ -546,9 +546,9 @@ unsigned int hashv;
if (c->hnext)
c->hnext->hprev = c->hprev;
MyFree(c->name);
MyFree(c->ip);
MyFree(c);
safe_free(c->name);
safe_free(c->ip);
safe_free(c);
unrealdns_num_cache--;
}
@ -577,21 +577,21 @@ struct hostent *unreal_create_hostent(char *name, char *ip)
struct hostent *he;
/* Create a hostent structure (I HATE HOSTENTS) and return it.. */
he = MyMallocEx(sizeof(struct hostent));
he = safe_alloc(sizeof(struct hostent));
he->h_name = strdup(name);
if (strchr(ip, ':'))
{
/* IPv6 */
he->h_addrtype = AF_INET6;
he->h_length = sizeof(struct in6_addr);
he->h_addr_list = MyMallocEx(sizeof(char *) * 2); /* alocate an array of 2 pointers */
he->h_addr_list[0] = MyMallocEx(sizeof(struct in6_addr));
he->h_addr_list = safe_alloc(sizeof(char *) * 2); /* alocate an array of 2 pointers */
he->h_addr_list[0] = safe_alloc(sizeof(struct in6_addr));
inet_pton(AF_INET6, ip, he->h_addr_list[0]);
} else {
he->h_addrtype = AF_INET;
he->h_length = sizeof(struct in_addr);
he->h_addr_list = MyMallocEx(sizeof(char *) * 2); /* alocate an array of 2 pointers */
he->h_addr_list[0] = MyMallocEx(sizeof(struct in_addr));
he->h_addr_list = safe_alloc(sizeof(char *) * 2); /* alocate an array of 2 pointers */
he->h_addr_list[0] = safe_alloc(sizeof(struct in_addr));
inet_pton(AF_INET, ip, he->h_addr_list[0]);
}
@ -600,10 +600,10 @@ struct hostent *he;
void unreal_free_hostent(struct hostent *he)
{
MyFree(he->h_name);
MyFree(he->h_addr_list[0]);
MyFree(he->h_addr_list);
MyFree(he);
safe_free(he->h_name);
safe_free(he->h_addr_list[0]);
safe_free(he->h_addr_list);
safe_free(he);
}
static void unrealdns_freeandremovereq(DNSReq *r)