ref: 78db7421d889f5af90135445bbdd996a5243e07d
parent: 9e1f7d750e447544d6893712d1bc25ba5d93e010
author: kemal <kemalinanc8@gmail.com>
date: Tue Oct 5 15:28:35 EDT 2021
ircs: remove redundant strdups, make emalloc global
--- /dev/null
+++ b/common.c
@@ -1,0 +1,15 @@
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "fns.h"
+
+void *
+emalloc(ulong n)
+{
+ void *p;
+
+ if(p = mallocz(n, 1), p == nil)
+ sysfatal("mallocz: not enough mem");
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
--- a/fns.h
+++ b/fns.h
@@ -1,3 +1,4 @@
+void* emalloc(ulong);
int ircparse(Ircmsg *, char *);
void ircprint(Ircmsg *);
int ircischan(char *);
--- a/irc.c
+++ b/irc.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include "dat.h"
+#include "fns.h"
static int
ircprefix(Ircmsg *irc)
--- a/list.c
+++ b/list.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include "dat.h"
+#include "fns.h"
int listallocs;
@@ -27,9 +28,7 @@
break;
if(l != nil)
return 0;
- l = mallocz(sizeof(List), 1);
- if(l == nil)
- sysfatal("mallocz: %r");
+ l = emalloc(sizeof(List));
listallocs++;
l->val = val;
l->next = *lp;
--- a/main.c
+++ b/main.c
@@ -77,23 +77,13 @@
static Trie *channels;
static Trie *users;
-static void *
-emalloc(ulong n)
-{
- void *p;
-
- p = mallocz(n, 1);
- if(p == nil)
- sysfatal("mallocz: %r");
- return p;
-}
-
static char *
estrdup(char *s)
{
s = strdup(s);
if(s == nil)
- sysfatal("strdup: %r");
+ sysfatal("strdup: not enough mem");
+ setmalloctag(s, getcallerpc(&s));
return s;
}
@@ -950,14 +940,14 @@
if(p = strchr(nickuser, '!')){
*p = 0;
if(*(++p) != 0)
- user = estrdup(p);
+ user = p;
else
- user = estrdup(nickuser);
+ user = nickuser;
} else
- user = estrdup(nickuser);
+ user = nickuser;
if(*nickuser != 0)
- mynick = estrdup(nickuser);
+ mynick = nickuser;
else
sysfatal("empty nick");
}
@@ -1005,7 +995,7 @@
userdb = 0;
if(service == nil)
- service = estrdup("ircs");
+ service = "ircs";
else if(*service == 0)
sysfatal("empty srvname");
--- a/mkfile
+++ b/mkfile
@@ -3,6 +3,7 @@
BIN=$home/bin/$objtype
TARG=ircs
OFILES=\
+ common.$O\
irc.$O\
ircfmt.$O\
list.$O\
--- a/trie.c
+++ b/trie.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include "dat.h"
+#include "fns.h"
int trieallocs;
int triedebug;
@@ -12,9 +13,7 @@
{
Trie *t;
- t = mallocz(sizeof(Trie), 1);
- if(t == nil)
- sysfatal("mallocz: %r");
+ t = emalloc(sizeof(Trie));
trieallocs++;
return t;
}