Commit a753a904 authored by Bernd Eckenfels's avatar Bernd Eckenfels

lib/util.c: introduxe xstrdup which catches NULL and use it in all places

parent e8510bc4
......@@ -208,8 +208,7 @@ void aftrans_def(char *tool, char *argv0, char *dflt)
else
tmp++;
if (!(buf = strdup(tmp)))
return;
buf = xstrdup(tmp);
if (strlen(tool) >= strlen(tmp)) {
free(buf);
......
......@@ -224,7 +224,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
pn->addr = *sin;
pn->next = INET_nn;
pn->host = host;
pn->name = strdup(name);
pn->name = xstrdup(name);
INET_nn = pn;
return (0);
......@@ -395,7 +395,7 @@ static int read_services(void)
while ((se = getservent())) {
/* Allocate a service entry. */
item = (struct service *) xmalloc(sizeof(struct service));
item->name = strdup(se->s_name);
item->name = xstrdup(se->s_name);
item->number = se->s_port;
/* Fill it in. */
......@@ -415,7 +415,7 @@ static int read_services(void)
while ((pe = getprotoent())) {
/* Allocate a service entry. */
item = (struct service *) xmalloc(sizeof(struct service));
item->name = strdup(pe->p_name);
item->name = xstrdup(pe->p_name);
item->number = htons(pe->p_proto);
add2list(&raw_name, item);
}
......
......@@ -45,8 +45,8 @@ int rindex_nondigit(char *name)
/* like strcmp(), but knows about numbers and ':' alias suffix */
int nstrcmp(const char *ap, const char *bp)
{
char *a = (char*)strdup(ap);
char *b = (char*)strdup(bp);
char *a = xstrdup(ap);
char *b = xstrdup(bp);
char *an, *bn;
int av = 0, bv = 0;
char *aalias=cutalias(a);
......
......@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include "util.h"
/* Caller must free return string. */
......@@ -48,7 +49,7 @@ char *proc_gen_fmt(char *name, int more, FILE * fh,...)
name, title);
return NULL;
}
return strdup(format);
return xstrdup(format);
}
/*
......
......@@ -22,6 +22,15 @@ void *xmalloc(size_t sz)
return p;
}
/* Like strdup, but oom() instead of NULL */
char *xstrdup(char *s)
{
char *d = strdup(s);
if (!d)
oom();
return d;
}
void *xrealloc(void *oldp, size_t sz)
{
void *p = realloc(oldp, sz);
......
......@@ -2,6 +2,7 @@
void *xmalloc(size_t sz);
void *xrealloc(void *p, size_t sz);
char *xstrdup(char *src);
#define new(p) ((p) = xmalloc(sizeof(*(p))))
......
......@@ -475,7 +475,7 @@ static void prg_cache_load(void)
snprintf(finbuf, sizeof(finbuf), "%s/%s", direproc->d_name, cmdlp);
#if HAVE_SELINUX
if (getpidcon(atoi(direproc->d_name), &scon) == -1) {
scon=strdup("-");
scon=xstrdup("-");
}
prg_cache_add(inode, finbuf, scon);
freecon(scon);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment