commit 8da59d1ff90b6963103e79ea238d3715aabe7871
parent b8ec059f11740c2d052e09690c88bd29d1f31ae8
Author: Kris Maglione <bsdaemon@wmii.de>
Date: Tue, 4 Jul 2006 18:00:11 -0400
Made use of malloc wrappers added in last commit
Diffstat:
8 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -182,8 +182,7 @@ write_buf(P9Req *r, void *buf, unsigned int len) {
len -= r->ifcall.offset;
if(len > r->ifcall.count)
len = r->ifcall.count;
- /* XXX: mallocz is not really needed here */
- r->ofcall.data = cext_emallocz(len);
+ r->ofcall.data = cext_emalloc(len);
memcpy(r->ofcall.data, buf + r->ifcall.offset, len);
r->ofcall.count = len;
}
@@ -206,8 +205,7 @@ write_to_buf(P9Req *r, void *buf, unsigned int *len, unsigned int max) {
*len = offset + count;
if(max == 0) {
- *(void **)buf = realloc(*(void **)buf, *len + 1);
- cext_assert(*(void **)buf);
+ *(void **)buf = cext_erealloc(*(void **)buf, *len + 1);
buf = *(void **)buf;
}
@@ -222,7 +220,7 @@ data_to_cstring(P9Req *r) {
unsigned int i;
i = r->ifcall.count;
if(!i || r->ifcall.data[i - 1] != '\n')
- r->ifcall.data = realloc(r->ifcall.data, ++i);
+ r->ifcall.data = cext_erealloc(r->ifcall.data, ++i);
cext_assert(r->ifcall.data);
r->ifcall.data[i - 1] = '\0';
}
@@ -270,7 +268,7 @@ message_root(char *message)
}else if(!strncmp(message, "font ", 5)) {
message += 5;
free(def.font.fontstr);
- def.font.fontstr = strdup(message);
+ def.font.fontstr = cext_estrdup(message);
blitz_loadfont(&blz, &def.font);
}else if(!strncmp(message, "border ", 7)) {
message += 7;
@@ -340,7 +338,7 @@ write_event(char *format, ...) {
for(f=pending_event_fids; f; f=f->next) {
fi = f->fid->aux;
slen = fi->buf ? strlen(fi->buf) : 0;
- fi->buf = realloc(fi->buf, slen + len + 1);
+ fi->buf = cext_erealloc(fi->buf, slen + len + 1);
fi->buf[slen] = '\0';
strcat(fi->buf, buffer);
}
@@ -402,7 +400,7 @@ lookup_file(FileId *parent, char *name)
file->id = c->id;
file->index = idx_of_client(c);
file->tab = *dir;
- file->tab.name = strdup("sel");
+ file->tab.name = cext_estrdup("sel");
}if(name) goto LastItem;
}
if(name) {
@@ -434,7 +432,7 @@ lookup_file(FileId *parent, char *name)
file->ref = screen->sel;
file->id = screen->sel->id;
file->tab = *dir;
- file->tab.name = strdup("sel");
+ file->tab.name = cext_estrdup("sel");
}if(name) goto LastItem;
}
for(v=view; v; v=v->next) {
@@ -445,7 +443,7 @@ lookup_file(FileId *parent, char *name)
file->ref = v;
file->id = v->id;
file->tab = *dir;
- file->tab.name = strdup(v->name);
+ file->tab.name = cext_estrdup(v->name);
if(name) goto LastItem;
}
}
@@ -459,7 +457,7 @@ lookup_file(FileId *parent, char *name)
file->ref = b;
file->id = b->id;
file->tab = *dir;
- file->tab.name = strdup(b->name);
+ file->tab.name = cext_estrdup(b->name);
if(name) goto LastItem;
}
}
@@ -474,7 +472,7 @@ lookup_file(FileId *parent, char *name)
file->ref = parent->ref;
file->index = parent->index;
file->tab = *dir;
- file->tab.name = strdup(file->tab.name);
+ file->tab.name = cext_estrdup(file->tab.name);
/* Special considerations: */
switch(file->tab.type) {
@@ -507,7 +505,7 @@ void
fs_attach(P9Req *r) {
FileId *f = get_file();
f->tab = dirtab[FsRoot][0];
- f->tab.name = strdup("/");
+ f->tab.name = cext_estrdup("/");
f->ref = nil; /* shut up valgrind */
r->fid->aux = f;
r->fid->qid.type = f->tab.qtype;
diff --git a/cmd/wm/view.c b/cmd/wm/view.c
@@ -190,7 +190,7 @@ restack_view(View *v)
for(c=client; c; c=c->next, i++);
if(i > winssz) {
winssz = 2 * i;
- wins = realloc(wins, sizeof(Window) * winssz);
+ wins = cext_erealloc(wins, sizeof(Window) * winssz);
}
for(a=v->area; a; a=a->next) {
diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c
@@ -280,7 +280,7 @@ main(int argc, char *argv[])
/* Check namespace permissions */
if(!strncmp(address, "unix!", 5)) {
struct stat st;
- namespace = strdup(&address[5]);
+ namespace = cext_estrdup(&address[5]);
for(i = strlen(namespace) - 1; i >= 0; i--)
if(namespace[i] == '/') break;
@@ -336,7 +336,7 @@ main(int argc, char *argv[])
key = nil;
passwd = getpwuid(getuid());
- user = strdup(passwd->pw_name);
+ user = cext_estrdup(passwd->pw_name);
def.colrules.string = nil;
def.colrules.size = 0;
@@ -344,7 +344,7 @@ main(int argc, char *argv[])
def.tagrules.size = 0;
def.keys = nil;
def.keyssz = 0;
- def.font.fontstr = strdup(BLITZ_FONT);
+ def.font.fontstr = cext_estrdup(BLITZ_FONT);
def.border = 2;
def.colmode = Coldefault;
cext_strlcpy(def.selcolor.colstr, BLITZ_SELCOLORS, sizeof(def.selcolor.colstr));
diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c
@@ -337,13 +337,13 @@ read_allitems()
len = strlen(buf);
if (buf[len - 1] == '\n')
buf[len - 1] = 0;
- p = strdup(buf);
+ p = cext_estrdup(buf);
if(max < len) {
maxname = p;
max = len;
}
- new = cext_emallocz(sizeof(Item));
+ new = cext_emalloc(sizeof(Item));
new->next = new->left = new->right = nil;
new->text = p;
if(!allitem)
@@ -408,7 +408,7 @@ main(int argc, char *argv[])
font.fontstr = getenv("WMII_FONT");
if (!font.fontstr)
- font.fontstr = strdup(BLITZ_FONT);
+ font.fontstr = cext_estrdup(BLITZ_FONT);
blitz_loadfont(&blz, &font);
if((p = getenv("WMII_NORMCOLORS")))
diff --git a/cmd/wmiir.c b/cmd/wmiir.c
@@ -204,10 +204,7 @@ xdir(char *file, int details)
return -1;
}
while((count = ixp_client_read(&c, fid, offset, result, IXP_MAX_MSG)) > 0) {
- if(!(data = realloc(data, offset + count))) {
- fprintf(stderr, "wmiir: %s\n", "Out of memory in xdir\n");
- return -1;
- }
+ data = cext_erealloc(data, offset + count);
memcpy(data + offset, result, count);
offset += count;
}
diff --git a/libixp/client.c b/libixp/client.c
@@ -43,7 +43,7 @@ ixp_client_dial(IXPClient *c, char *sockfile, unsigned int rootfid)
c->fcall.type = TVERSION;
c->fcall.tag = IXP_NOTAG;
c->fcall.msize = IXP_MAX_MSG;
- c->fcall.version = strdup(IXP_VERSION);
+ c->fcall.version = cext_estrdup(IXP_VERSION);
if(ixp_client_do_fcall(c) == -1) {
fprintf(stderr, "error: %s\n", c->errstr);
ixp_client_hangup(c);
@@ -61,8 +61,8 @@ ixp_client_dial(IXPClient *c, char *sockfile, unsigned int rootfid)
c->fcall.tag = IXP_NOTAG;
c->fcall.fid = c->root_fid;
c->fcall.afid = IXP_NOFID;
- c->fcall.uname = strdup(getenv("USER"));
- c->fcall.aname = strdup("");
+ c->fcall.uname = cext_estrdup(getenv("USER"));
+ c->fcall.aname = cext_estrdup("");
if(ixp_client_do_fcall(c) == -1) {
fprintf(stderr, "error: %s\n", c->errstr);
ixp_client_hangup(c);
@@ -90,7 +90,7 @@ ixp_client_create(IXPClient *c, unsigned int dirfid, char *name,
c->fcall.type = TCREATE;
c->fcall.tag = IXP_NOTAG;
c->fcall.fid = dirfid;
- c->fcall.name = strdup(name);
+ c->fcall.name = cext_estrdup(name);
c->fcall.perm = perm;
c->fcall.mode = mode;
return ixp_client_do_fcall(c);
@@ -105,11 +105,11 @@ ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath)
c->fcall.fid = c->root_fid;
c->fcall.newfid = newfid;
if(filepath) {
- c->fcall.name = strdup(filepath);
+ c->fcall.name = cext_estrdup(filepath);
c->fcall.nwname =
cext_tokenize(wname, IXP_MAX_WELEM, c->fcall.name, '/');
for(i = 0; i < c->fcall.nwname; i++)
- c->fcall.wname[i] = strdup(wname[i]);
+ c->fcall.wname[i] = cext_estrdup(wname[i]);
}
return ixp_client_do_fcall(c);
}
diff --git a/libixp/convert.c b/libixp/convert.c
@@ -117,8 +117,7 @@ ixp_unpack_strings(unsigned char **msg, int *msize, unsigned short n, char **str
*strings = nil;
return;
}
- /* XXX: we don't really need mallocz here */
- s = cext_emallocz(size);
+ s = cext_emalloc(size);
for(i=0; i < n; i++) {
ixp_unpack_u16(msg, msize, &len);
if(!msize || (*msize -= len) < 0)
@@ -138,8 +137,7 @@ ixp_unpack_string(unsigned char **msg, int *msize, char **string, unsigned short
ixp_unpack_u16(msg, msize, len);
*string = nil;
if (!msize || (*msize -= *len) >= 0) {
- /* XXX we don't really need emallocz here */
- *string = cext_emallocz(*len+1);
+ *string = cext_emalloc(*len+1);
if(*len)
memcpy(*string, *msg, *len);
(*string)[*len] = 0;
diff --git a/liblitz/input.c b/liblitz/input.c
@@ -66,7 +66,7 @@ blitz_setinput(BlitzInput *i, char *text)
i->len = strlen(text);
if(i->len + 1 > i->size) {
i->size = 2 * i->len + 1;
- i->text = realloc(i->text, i->size);
+ i->text = cext_erealloc(i->text, i->size);
}
memcpy(i->text, text, i->len);
i->text[i->len] = 0;
@@ -355,7 +355,7 @@ blitz_kpress_input(BlitzInput *i, unsigned long mod, KeySym k, char *ks)
s = start - i->text;
e = end - i->text;
i->size = 2 * i->len + 1;
- i->text = realloc(i->text, i->size);
+ i->text = cext_erealloc(i->text, i->size);
start = i->text + s;
end = i->text + e;
}