summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2005-12-10 20:27:47 +0000
committerJoris Vink <joris@cvs.openbsd.org>2005-12-10 20:27:47 +0000
commit9eb5d4f85893529cdca5a54796e344ecb6581196 (patch)
treef6078dc6aa0b2687219c6431ba7f872b4326c298 /usr.bin/cvs
parentcc2c3fa0314517ddf972b8ca44e9d25aee920bc1 (diff)
switch to xmalloc stuff, me and xsa@ agreed on this a long
time ago, but we were being held back by jfb. too bad for him. next step is to use fatal() through out the code for unrecoverable errors instead of trying to be all nice and fluffy and reach main() again. ok niallo@ and xsa@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/Makefile6
-rw-r--r--usr.bin/cvs/add.c7
-rw-r--r--usr.bin/cvs/buf.c32
-rw-r--r--usr.bin/cvs/cmd.c9
-rw-r--r--usr.bin/cvs/commit.c8
-rw-r--r--usr.bin/cvs/cvs.c48
-rw-r--r--usr.bin/cvs/cvs.h6
-rw-r--r--usr.bin/cvs/diff.c108
-rw-r--r--usr.bin/cvs/diff3.c27
-rw-r--r--usr.bin/cvs/entries.c49
-rw-r--r--usr.bin/cvs/fatal.c41
-rw-r--r--usr.bin/cvs/file.c129
-rw-r--r--usr.bin/cvs/hist.c24
-rw-r--r--usr.bin/cvs/import.c8
-rw-r--r--usr.bin/cvs/log.c4
-rw-r--r--usr.bin/cvs/logmsg.c4
-rw-r--r--usr.bin/cvs/proto.c26
-rw-r--r--usr.bin/cvs/rcs.c354
-rw-r--r--usr.bin/cvs/rcsnum.c41
-rw-r--r--usr.bin/cvs/req.c36
-rw-r--r--usr.bin/cvs/resp.c22
-rw-r--r--usr.bin/cvs/root.c29
-rw-r--r--usr.bin/cvs/util.c67
-rw-r--r--usr.bin/cvs/watch.c13
-rw-r--r--usr.bin/cvs/xmalloc.c67
-rw-r--r--usr.bin/cvs/xmalloc.h27
-rw-r--r--usr.bin/cvs/zlib.c8
27 files changed, 436 insertions, 764 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile
index a64c7f3349a..ec09208b5c6 100644
--- a/usr.bin/cvs/Makefile
+++ b/usr.bin/cvs/Makefile
@@ -1,14 +1,14 @@
-# $OpenBSD: Makefile,v 1.16 2005/11/12 21:34:48 niallo Exp $
+# $OpenBSD: Makefile,v 1.17 2005/12/10 20:27:45 joris Exp $
PROG= cvs
MAN= cvs.1 cvsignore.5 cvsrc.5 cvswrappers.5 cvsintro.7
CPPFLAGS+=-I${.CURDIR}
SRCS= cvs.c add.c admin.c annotate.c buf.c checkout.c cmd.c commit.c date.y \
- diff.c diff3.c edit.c entries.c file.c getlog.c history.c hist.c \
+ diff.c diff3.c edit.c entries.c fatal.c file.c getlog.c history.c hist.c \
import.c init.c log.c logmsg.c proto.c rcs.c rcsnum.c release.c \
remove.c req.c resp.c root.c server.c status.c tag.c \
- update.c util.c version.c watch.c
+ update.c util.c version.c watch.c xmalloc.c
CFLAGS= -g -ggdb
CFLAGS+= -Wall
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c
index 7c96a2bb840..0b8d3b57730 100644
--- a/usr.bin/cvs/add.c
+++ b/usr.bin/cvs/add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: add.c,v 1.34 2005/10/07 21:47:32 reyk Exp $ */
+/* $OpenBSD: add.c,v 1.35 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
@@ -90,10 +90,7 @@ cvs_add_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
}
break;
case 'm':
- if ((cvs_msg = strdup(optarg)) == NULL) {
- cvs_log(LP_ERRNO, "failed to copy message");
- return (CVS_EX_DATA);
- }
+ cvs_msg = xstrdup(optarg);
break;
default:
return (CVS_EX_USAGE);
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c
index 5cb31d562a0..7645a093ac9 100644
--- a/usr.bin/cvs/buf.c
+++ b/usr.bin/cvs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.18 2005/08/14 19:49:18 xsa Exp $ */
+/* $OpenBSD: buf.c,v 1.19 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -38,7 +38,7 @@
#include "buf.h"
#include "log.h"
-
+#include "xmalloc.h"
#define BUF_INCR 128
@@ -76,18 +76,8 @@ cvs_buf_alloc(size_t len, u_int flags)
{
BUF *b;
- b = (BUF *)malloc(sizeof(*b));
- if (b == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate buffer");
- return (NULL);
- }
-
- b->cb_buf = malloc(len);
- if (b->cb_buf == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate buffer");
- free(b);
- return (NULL);
- }
+ b = (BUF *)xmalloc(sizeof(*b));
+ b->cb_buf = xmalloc(len);
memset(b->cb_buf, 0, len);
b->cb_flags = flags;
@@ -162,8 +152,8 @@ cvs_buf_load(const char *path, u_int flags)
void
cvs_buf_free(BUF *b)
{
- free(b->cb_buf);
- free(b);
+ xfree(b->cb_buf);
+ xfree(b);
}
@@ -180,7 +170,7 @@ cvs_buf_release(BUF *b)
u_char *tmp;
tmp = b->cb_buf;
- free(b);
+ xfree(b);
return (tmp);
}
@@ -339,7 +329,7 @@ cvs_buf_fappend(BUF *b, const char *fmt, ...)
}
ret = cvs_buf_append(b, str, (size_t)ret);
- free(str);
+ xfree(str);
return (ret);
}
@@ -473,11 +463,7 @@ cvs_buf_grow(BUF *b, size_t len)
size_t diff;
diff = b->cb_cur - b->cb_buf;
- tmp = realloc(b->cb_buf, b->cb_size + len);
- if (tmp == NULL) {
- cvs_log(LP_ERRNO, "failed to grow buffer");
- return (-1);
- }
+ tmp = xrealloc(b->cb_buf, b->cb_size + len);
b->cb_buf = (u_char *)tmp;
b->cb_size += len;
diff --git a/usr.bin/cvs/cmd.c b/usr.bin/cvs/cmd.c
index bcb7a6fdec9..15f30b8b8ee 100644
--- a/usr.bin/cvs/cmd.c
+++ b/usr.bin/cvs/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.38 2005/12/03 01:02:08 joris Exp $ */
+/* $OpenBSD: cmd.c,v 1.39 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -230,11 +230,8 @@ cvs_startcmd(struct cvs_cmd *cmd, int argc, char **argv)
* This allows us to correctly fill in the repository
* string for CVSFILE's fetched inside the repository itself.
*/
- if (cvs_cmdop == CVS_OP_SERVER) {
- cvs_rootstr = strdup(root->cr_str);
- if (cvs_rootstr == NULL)
- return (CVS_EX_DATA);
- }
+ if (cvs_cmdop == CVS_OP_SERVER)
+ cvs_rootstr = xstrdup(root->cr_str);
cvs_log(LP_TRACE, "cvs_startcmd() CVSROOT=%s", root->cr_str);
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index f09ebb0e092..245725337ee 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.46 2005/07/27 16:42:19 xsa Exp $ */
+/* $OpenBSD: commit.c,v 1.47 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -88,11 +88,7 @@ cvs_commit_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
cmd->file_flags &= ~CF_RECURSE;
break;
case 'm':
- cvs_msg = strdup(optarg);
- if (cvs_msg == NULL) {
- cvs_log(LP_ERRNO, "failed to copy message");
- return (CVS_EX_USAGE);
- }
+ cvs_msg = xstrdup(optarg);
break;
case 'R':
cmd->file_flags |= CF_RECURSE;
diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c
index 3fcdfc254fc..7f612698f61 100644
--- a/usr.bin/cvs/cvs.c
+++ b/usr.bin/cvs/cvs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.c,v 1.87 2005/12/03 15:07:20 joris Exp $ */
+/* $OpenBSD: cvs.c,v 1.88 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -180,7 +180,7 @@ main(int argc, char **argv)
cvs_getopt(i, targv);
cvs_freeargv(targv, i);
- free(targv);
+ xfree(targv);
}
}
@@ -256,7 +256,7 @@ main(int argc, char **argv)
if (cvs_files != NULL)
cvs_file_free(cvs_files);
if (cvs_msg != NULL)
- free(cvs_msg);
+ xfree(cvs_msg);
return (ret);
}
@@ -419,10 +419,7 @@ cvs_read_rcfile(void)
* argument processing.
*/
*lp = ' ';
- cvs_defargs = strdup(p);
- if (cvs_defargs == NULL)
- cvs_log(LP_ERRNO,
- "failed to copy global arguments");
+ cvs_defargs = xstrdup(p);
} else {
lp++;
cmdp = cvs_findcmd(p);
@@ -433,11 +430,7 @@ cvs_read_rcfile(void)
continue;
}
- cmdp->cmd_defargs = strdup(lp);
- if (cmdp->cmd_defargs == NULL)
- cvs_log(LP_ERRNO,
- "failed to copy default arguments for %s",
- cmdp->cmd_name);
+ cmdp->cmd_defargs = xstrdup(lp);
}
}
if (ferror(fp)) {
@@ -480,33 +473,16 @@ cvs_var_set(const char *var, const char *val)
if (strcmp(vp->cv_name, var) == 0)
break;
- valcp = strdup(val);
- if (valcp == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate variable");
- return (-1);
- }
-
+ valcp = xstrdup(val);
if (vp == NULL) {
- vp = (struct cvs_var *)malloc(sizeof(*vp));
- if (vp == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate variable");
- free(valcp);
- return (-1);
- }
+ vp = (struct cvs_var *)xmalloc(sizeof(*vp));
memset(vp, 0, sizeof(*vp));
- vp->cv_name = strdup(var);
- if (vp->cv_name == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate variable");
- free(valcp);
- free(vp);
- return (-1);
- }
-
+ vp->cv_name = xstrdup(var);
TAILQ_INSERT_TAIL(&cvs_variables, vp, cv_link);
} else /* free the previous value */
- free(vp->cv_val);
+ xfree(vp->cv_val);
vp->cv_val = valcp;
@@ -528,9 +504,9 @@ cvs_var_unset(const char *var)
TAILQ_FOREACH(vp, &cvs_variables, cv_link)
if (strcmp(vp->cv_name, var) == 0) {
TAILQ_REMOVE(&cvs_variables, vp, cv_link);
- free(vp->cv_name);
- free(vp->cv_val);
- free(vp);
+ xfree(vp->cv_name);
+ xfree(vp->cv_val);
+ xfree(vp);
return (0);
}
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 24914141c1d..9385e214a8b 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.90 2005/12/03 15:07:21 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.91 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -34,6 +34,7 @@
#include "rcs.h"
#include "file.h"
+#include "xmalloc.h"
#define CVS_VERSION_MAJOR 0
#define CVS_VERSION_MINOR 3
@@ -427,6 +428,7 @@ struct cvs_lines {
struct cvs_tqh l_lines;
};
+void fatal(const char *, ...);
int cvs_readrepo(const char *, char *, size_t);
int cvs_modetostr(mode_t, char *, size_t);
int cvs_strtomode(const char *, mode_t *);
@@ -458,4 +460,4 @@ void cvs_freelines(struct cvs_lines *);
int rcs_patch_lines(struct cvs_lines *, struct cvs_lines *);
int cvs_checkout_rev(RCSFILE *, RCSNUM *, CVSFILE *, char *, int, int, ...);
-#endif /* CVS_H */
+#endif
diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c
index 74cc60b601f..019ae38148b 100644
--- a/usr.bin/cvs/diff.c
+++ b/usr.bin/cvs/diff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff.c,v 1.70 2005/12/05 19:53:00 niallo Exp $ */
+/* $OpenBSD: diff.c,v 1.71 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
* All rights reserved.
@@ -357,9 +357,7 @@ cvs_diff_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
{
int ch;
- dap = (struct diff_arg *)malloc(sizeof(*dap));
- if (dap == NULL)
- return (CVS_EX_DATA);
+ dap = (struct diff_arg *)xmalloc(sizeof(*dap));
dap->date1 = dap->date2 = dap->rev1 = dap->rev2 = NULL;
strlcpy(diffargs, argv[0], sizeof(diffargs));
@@ -434,7 +432,7 @@ int
cvs_diff_cleanup(void)
{
if (dap != NULL) {
- free(dap);
+ xfree(dap);
dap = NULL;
}
return (0);
@@ -767,65 +765,35 @@ cvs_diffreg(const char *file1, const char *file2, BUF *out)
member = (int *)file[1];
equiv(sfile[0], slen[0], sfile[1], slen[1], member);
- if ((tmp = realloc(member, (slen[1] + 2) * sizeof(int))) == NULL) {
- free(member);
- member = NULL;
- cvs_log(LP_ERRNO, "failed to resize member");
- goto closem;
- }
+ tmp = xrealloc(member, (slen[1] + 2) * sizeof(int));
member = (int *)tmp;
class = (int *)file[0];
unsort(sfile[0], slen[0], class);
- if ((tmp = realloc(class, (slen[0] + 2) * sizeof(int))) == NULL) {
- free(class);
- class = NULL;
- cvs_log(LP_ERRNO, "failed to resize class");
- goto closem;
- }
+ tmp = xrealloc(class, (slen[0] + 2) * sizeof(int));
class = (int *)tmp;
- if ((klist = malloc((slen[0] + 2) * sizeof(int))) == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate klist");
- goto closem;
- }
+ klist = xmalloc((slen[0] + 2) * sizeof(int));
clen = 0;
clistlen = 100;
- if ((clist = malloc(clistlen * sizeof(cand))) == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate clist");
- goto closem;
- }
+ clist = xmalloc(clistlen * sizeof(cand));
if ((i = stone(class, slen[0], member, klist)) < 0)
goto closem;
- free(member);
- free(class);
+ xfree(member);
+ xfree(class);
- if ((tmp = realloc(J, (diff_len[0] + 2) * sizeof(int))) == NULL) {
- free(J);
- J = NULL;
- cvs_log(LP_ERRNO, "failed to resize J");
- goto closem;
- }
+ tmp = xrealloc(J, (diff_len[0] + 2) * sizeof(int));
J = (int *)tmp;
unravel(klist[i]);
- free(clist);
- free(klist);
+ xfree(clist);
+ xfree(klist);
- if ((tmp = realloc(ixold, (diff_len[0] + 2) * sizeof(long))) == NULL) {
- free(ixold);
- ixold = NULL;
- cvs_log(LP_ERRNO, "failed to resize ixold");
- goto closem;
- }
+ tmp = xrealloc(ixold, (diff_len[0] + 2) * sizeof(long));
ixold = (long *)tmp;
- if ((tmp = realloc(ixnew, (diff_len[1] + 2) * sizeof(long))) == NULL) {
- free(ixnew);
- ixnew = NULL;
- cvs_log(LP_ERRNO, "failed to resize ixnew");
- goto closem;
- }
+
+ tmp = xrealloc(ixnew, (diff_len[1] + 2) * sizeof(long));
ixnew = (long *)tmp;
check(f1, f2);
output(file1, f1, file2, f2);
@@ -885,20 +853,11 @@ prepare(int i, FILE *fd, off_t filesize)
if (sz < 100)
sz = 100;
- p = (struct line *)malloc((sz + 3) * sizeof(struct line));
- if (p == NULL) {
- cvs_log(LP_ERRNO, "failed to prepare line array");
- return (-1);
- }
+ p = (struct line *)xmalloc((sz + 3) * sizeof(struct line));
for (j = 0; (h = readhash(fd));) {
if (j == (int)sz) {
sz = sz * 3 / 2;
- tmp = realloc(p, (sz + 3) * sizeof(struct line));
- if (tmp == NULL) {
- cvs_log(LP_ERRNO, "failed to grow line array");
- free(p);
- return (-1);
- }
+ tmp = xrealloc(p, (sz + 3) * sizeof(struct line));
p = (struct line *)tmp;
}
p[++j].value = h;
@@ -1038,11 +997,7 @@ newcand(int x, int y, int pred)
if (clen == clistlen) {
newclistlen = clistlen * 11 / 10;
- tmp = realloc(clist, newclistlen * sizeof(cand));
- if (tmp == NULL) {
- cvs_log(LP_ERRNO, "failed to resize clist");
- return (-1);
- }
+ tmp = xrealloc(clist, newclistlen * sizeof(cand));
clist = tmp;
clistlen = newclistlen;
}
@@ -1232,15 +1187,12 @@ unsort(struct line *f, int l, int *b)
{
int *a, i;
- if ((a = (int *)malloc((l + 1) * sizeof(int))) == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate sort array");
- return;
- }
+ a = (int *)xmalloc((l + 1) * sizeof(int));
for (i = 1; i <= l; i++)
a[f[i].serial] = f[i].value;
for (i = 1; i <= l; i++)
b[i] = a[i];
- free(a);
+ xfree(a);
}
static int
@@ -1318,11 +1270,7 @@ preadline(int fd, size_t rlen, off_t off)
char *line;
ssize_t nr;
- line = malloc(rlen + 1);
- if (line == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate line");
- return (NULL);
- }
+ line = xmalloc(rlen + 1);
if ((nr = pread(fd, line, rlen, off)) < 0) {
cvs_log(LP_ERRNO, "preadline failed");
return (NULL);
@@ -1337,7 +1285,7 @@ ignoreline(char *line)
int ret;
ret = regexec(&ignore_re, line, (size_t)0, NULL, 0);
- free(line);
+ xfree(line);
return (ret == 0); /* if it matched, it should be ignored. */
}
@@ -1391,14 +1339,8 @@ proceed:
struct context_vec *tmp;
ptrdiff_t offset = context_vec_ptr - context_vec_start;
max_context <<= 1;
- if ((tmp = realloc(context_vec_start, max_context *
- sizeof(struct context_vec))) == NULL) {
- free(context_vec_start);
- context_vec_start = NULL;
- cvs_log(LP_ERRNO,
- "failed to resize context_vec_start");
- return;
- }
+ tmp = xrealloc(context_vec_start, max_context *
+ sizeof(struct context_vec));
context_vec_start = tmp;
context_vec_end = context_vec_start + max_context;
context_vec_ptr = context_vec_start + offset;
@@ -1836,6 +1778,6 @@ diff_output(const char *fmt, ...)
cvs_buf_append(diffbuf, str, strlen(str));
else
cvs_printf("%s", str);
- free(str);
+ xfree(str);
va_end(vap);
}
diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c
index 498b4dcc780..45c39e4a02f 100644
--- a/usr.bin/cvs/diff3.c
+++ b/usr.bin/cvs/diff3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diff3.c,v 1.7 2005/12/03 01:02:08 joris Exp $ */
+/* $OpenBSD: diff3.c,v 1.8 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -71,7 +71,7 @@ static const char copyright[] =
#endif /* not lint */
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diff3.c,v 1.7 2005/12/03 01:02:08 joris Exp $";
+static const char rcsid[] = "$OpenBSD: diff3.c,v 1.8 2005/12/10 20:27:45 joris Exp $";
#endif /* not lint */
#include <sys/queue.h>
@@ -270,8 +270,8 @@ cvs_diff3(RCSFILE *rf, char *workfile, RCSNUM *rev1, RCSNUM *rev2)
diff3_conflicts, (diff3_conflicts > 1) ? "s" : "");
}
- free(data);
- free(patch);
+ xfree(data);
+ xfree(patch);
out:
if (b1 != NULL)
@@ -508,8 +508,7 @@ getline(FILE *b, size_t *n)
do {
bufsize += 1024;
} while (len + 1 > bufsize);
- if ((buf = realloc(buf, bufsize)) == NULL)
- err(EXIT_FAILURE, NULL);
+ buf = xrealloc(buf, bufsize);
}
memcpy(buf, cp, len - 1);
buf[len - 1] = '\n';
@@ -808,24 +807,16 @@ increase(void)
newsz = szchanges == 0 ? 64 : 2 * szchanges;
incr = newsz - szchanges;
- p = realloc(d13, newsz * sizeof(struct diff));
- if (p == NULL)
- err(1, NULL);
+ p = xrealloc(d13, newsz * sizeof(struct diff));
memset(p + szchanges, 0, incr * sizeof(struct diff));
d13 = p;
- p = realloc(d23, newsz * sizeof(struct diff));
- if (p == NULL)
- err(1, NULL);
+ p = xrealloc(d23, newsz * sizeof(struct diff));
memset(p + szchanges, 0, incr * sizeof(struct diff));
d23 = p;
- p = realloc(de, newsz * sizeof(struct diff));
- if (p == NULL)
- err(1, NULL);
+ p = xrealloc(de, newsz * sizeof(struct diff));
memset(p + szchanges, 0, incr * sizeof(struct diff));
de = p;
- q = realloc(overlap, newsz * sizeof(char));
- if (q == NULL)
- err(1, NULL);
+ q = xrealloc(overlap, newsz * sizeof(char));
memset(q + szchanges, 0, incr * sizeof(char));
overlap = q;
szchanges = newsz;
diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c
index 1ece81f0864..541872b87c3 100644
--- a/usr.bin/cvs/entries.c
+++ b/usr.bin/cvs/entries.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entries.c,v 1.52 2005/12/03 15:02:55 joris Exp $ */
+/* $OpenBSD: entries.c,v 1.53 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -112,29 +112,11 @@ cvs_ent_open(const char *dir, int flags)
return (NULL);
}
- ep = (CVSENTRIES *)malloc(sizeof(CVSENTRIES));
- if (ep == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate Entries data");
- (void)fclose(fp);
- return (NULL);
- }
+ ep = (CVSENTRIES *)xmalloc(sizeof(CVSENTRIES));
memset(ep, 0, sizeof(*ep));
- ep->cef_path = strdup(entpath);
- if (ep->cef_path == NULL) {
- cvs_log(LP_ERRNO, "failed to copy Entries path");
- free(ep);
- (void)fclose(fp);
- return (NULL);
- }
-
- ep->cef_bpath = strdup(bpath);
- if (ep->cef_bpath == NULL) {
- cvs_ent_close(ep);
- (void)fclose(fp);
- return (NULL);
- }
-
+ ep->cef_path = xstrdup(entpath);
+ ep->cef_bpath = xstrdup(bpath);
ep->cef_cur = NULL;
TAILQ_INIT(&(ep->cef_ent));
@@ -224,10 +206,10 @@ cvs_ent_close(CVSENTRIES *ep)
}
if (ep->cef_path != NULL)
- free(ep->cef_path);
+ xfree(ep->cef_path);
if (ep->cef_bpath != NULL)
- free(ep->cef_bpath);
+ xfree(ep->cef_bpath);
while (!TAILQ_EMPTY(&(ep->cef_ent))) {
ent = TAILQ_FIRST(&(ep->cef_ent));
@@ -235,7 +217,7 @@ cvs_ent_close(CVSENTRIES *ep)
cvs_ent_free(ent);
}
- free(ep);
+ xfree(ep);
}
@@ -389,12 +371,7 @@ cvs_ent_parse(const char *entry)
char *fields[CVS_ENTRIES_NFIELDS], *buf, *sp, *dp;
struct cvs_ent *ent;
- buf = strdup(entry);
- if (buf == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate entry copy");
- return (NULL);
- }
-
+ buf = xstrdup(entry);
sp = buf;
i = 0;
do {
@@ -410,11 +387,7 @@ cvs_ent_parse(const char *entry)
return (NULL);
}
- ent = (struct cvs_ent *)malloc(sizeof(*ent));
- if (ent == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate CVS entry");
- return (NULL);
- }
+ ent = (struct cvs_ent *)xmalloc(sizeof(*ent));
memset(ent, 0, sizeof(*ent));
ent->ce_buf = buf;
@@ -472,8 +445,8 @@ cvs_ent_free(struct cvs_ent *ent)
if (ent->ce_rev != NULL)
rcsnum_free(ent->ce_rev);
if (ent->ce_buf != NULL)
- free(ent->ce_buf);
- free(ent);
+ xfree(ent->ce_buf);
+ xfree(ent);
}
/*
diff --git a/usr.bin/cvs/fatal.c b/usr.bin/cvs/fatal.c
new file mode 100644
index 00000000000..40e997a57a7
--- /dev/null
+++ b/usr.bin/cvs/fatal.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2002 Markus Friedl. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "cvs.h"
+#include "log.h"
+
+/* Fatal messages. This function never returns. */
+
+void
+fatal(const char *fmt,...)
+{
+ va_list args;
+ va_start(args, fmt);
+ cvs_log(LP_ERR, fmt, args);
+ va_end(args);
+ exit(255);
+}
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index d699645190e..231dde64606 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.131 2005/12/04 17:39:02 joris Exp $ */
+/* $OpenBSD: file.c,v 1.132 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -181,12 +181,7 @@ cvs_file_ignore(const char *pat)
char *cp;
struct cvs_ignpat *ip;
- ip = (struct cvs_ignpat *)malloc(sizeof(*ip));
- if (ip == NULL) {
- cvs_log(LP_ERR, "failed to allocate space for ignore pattern");
- return (-1);
- }
-
+ ip = (struct cvs_ignpat *)xmalloc(sizeof(*ip));
strlcpy(ip->ip_pat, pat, sizeof(ip->ip_pat));
/* check if we will need globbing for that pattern */
@@ -278,12 +273,7 @@ cvs_file_create(CVSFILE *parent, const char *path, u_int type, mode_t mode)
return (NULL);
}
- cfp->cf_repo = strdup(repo);
- if (cfp->cf_repo == NULL) {
- cvs_file_free(cfp);
- return (NULL);
- }
-
+ cfp->cf_repo = xstrdup(repo);
if (((mkdir(path, mode) == -1) && (errno != EEXIST)) ||
(cvs_mkadmin(path, cfp->cf_root->cr_str, cfp->cf_repo,
NULL, NULL, 0) < 0)) {
@@ -405,25 +395,15 @@ cvs_file_getspec(char **fspec, int fsn, int flags, int (*cb)(CVSFILE *, void *),
*/
if (cf->cf_repo != NULL) {
if (cvs_repo_base != NULL)
- free(cvs_repo_base);
- cvs_repo_base = strdup(cf->cf_repo);
- if (cvs_repo_base == NULL) {
- cvs_log(LP_ERRNO, "strdup failed");
- cvs_file_free(cf);
- return (-1);
- }
+ xfree(cvs_repo_base);
+ cvs_repo_base = xstrdup(cf->cf_repo);
}
/*
* This will go away when we have support for multiple Roots.
*/
if (cvs_rootstr == NULL && cf->cf_root != NULL) {
- cvs_rootstr = strdup(cf->cf_root->cr_str);
- if (cvs_rootstr == NULL) {
- cvs_log(LP_ERRNO, "strdup failed");
- cvs_file_free(cf);
- return (-1);
- }
+ cvs_rootstr = xstrdup(cf->cf_root->cr_str);
}
cvs_error = CVS_EX_OK;
@@ -789,14 +769,8 @@ cvs_load_dirinfo(CVSFILE *cf, int flags)
}
if ((stat(pbuf, &st) == 0) && S_ISDIR(st.st_mode)) {
- if (cvs_readrepo(fpath, pbuf, sizeof(pbuf)) == 0) {
- cf->cf_repo = strdup(pbuf);
- if (cf->cf_repo == NULL) {
- cvs_log(LP_ERRNO,
- "failed to dup repository string");
- return (-1);
- }
- }
+ if (cvs_readrepo(fpath, pbuf, sizeof(pbuf)) == 0)
+ cf->cf_repo = xstrdup(pbuf);
} else {
/*
* Fill in the repo path ourselfs.
@@ -807,11 +781,7 @@ cvs_load_dirinfo(CVSFILE *cf, int flags)
if (l == -1 || l >= (int)sizeof(pbuf))
return (-1);
- cf->cf_repo = strdup(pbuf);
- if (cf->cf_repo == NULL) {
- cvs_log(LP_ERRNO, "failed to dup repo string");
- return (-1);
- }
+ cf->cf_repo = xstrdup(pbuf);
} else
cf->cf_repo = NULL;
}
@@ -855,9 +825,8 @@ cvs_file_getdir(CVSFILE *cf, int flags, int (*cb)(CVSFILE *, void *),
(cf->cf_dir != NULL) ? cf->cf_dir : "");
if (ret == -1 || ret >= (int)sizeof(fpath))
return (-1);
- free(cf->cf_dir);
- if ((cf->cf_dir = strdup(fpath)) == NULL)
- return (-1);
+ xfree(cf->cf_dir);
+ cf->cf_dir = xstrdup(fpath);
}
nfiles = ndirs = 0;
@@ -1052,16 +1021,16 @@ cvs_file_free(CVSFILE *cf)
CVSFILE *child;
if (cf->cf_name != NULL)
- free(cf->cf_name);
+ xfree(cf->cf_name);
if (cf->cf_dir != NULL)
- free(cf->cf_dir);
+ xfree(cf->cf_dir);
if (cf->cf_type == DT_DIR) {
if (cf->cf_root != NULL)
cvsroot_remove(cf->cf_root);
if (cf->cf_repo != NULL)
- free(cf->cf_repo);
+ xfree(cf->cf_repo);
while (!SIMPLEQ_EMPTY(&(cf->cf_files))) {
child = SIMPLEQ_FIRST(&(cf->cf_files));
SIMPLEQ_REMOVE_HEAD(&(cf->cf_files), cf_list);
@@ -1069,12 +1038,12 @@ cvs_file_free(CVSFILE *cf)
}
} else {
if (cf->cf_tag != NULL)
- free(cf->cf_tag);
+ xfree(cf->cf_tag);
if (cf->cf_opts != NULL)
- free(cf->cf_opts);
+ xfree(cf->cf_opts);
}
- free(cf);
+ xfree(cf);
}
@@ -1106,7 +1075,7 @@ cvs_file_sort(struct cvs_flist *flp, u_int nfiles)
/* rebuild the list and abort sorting */
while (--i >= 0)
SIMPLEQ_INSERT_HEAD(flp, cfvec[i], cf_list);
- free(cfvec);
+ xfree(cfvec);
return (-1);
}
cfvec[i++] = cf;
@@ -1127,7 +1096,7 @@ cvs_file_sort(struct cvs_flist *flp, u_int nfiles)
for (i = (int)nb - 1; i >= 0; i--)
SIMPLEQ_INSERT_HEAD(flp, cfvec[i], cf_list);
- free(cfvec);
+ xfree(cfvec);
return (0);
}
@@ -1153,11 +1122,7 @@ cvs_file_alloc(const char *path, u_int type)
CVSFILE *cfp;
char *p;
- cfp = (CVSFILE *)malloc(sizeof(*cfp));
- if (cfp == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate CVS file data");
- return (NULL);
- }
+ cfp = (CVSFILE *)xmalloc(sizeof(*cfp));
memset(cfp, 0, sizeof(*cfp));
cfp->cf_type = type;
@@ -1167,24 +1132,12 @@ cvs_file_alloc(const char *path, u_int type)
SIMPLEQ_INIT(&(cfp->cf_files));
}
- cfp->cf_name = strdup(basename(path));
- if (cfp->cf_name == NULL) {
- cvs_log(LP_ERR, "failed to copy file name");
- cvs_file_free(cfp);
- return (NULL);
- }
-
+ cfp->cf_name = xstrdup(basename(path));
if ((p = strrchr(path, '/')) != NULL) {
*p = '\0';
- if (strcmp(path, ".")) {
- cfp->cf_dir = strdup(path);
- if (cfp->cf_dir == NULL) {
- cvs_log(LP_ERR,
- "failed to copy directory");
- cvs_file_free(cfp);
- return (NULL);
- }
- } else
+ if (strcmp(path, "."))
+ cfp->cf_dir = xstrdup(path);
+ else
cfp->cf_dir = NULL;
*p = '/';
} else
@@ -1301,21 +1254,11 @@ cvs_file_lget(const char *path, int flags, CVSFILE *parent, CVSENTRIES *pent,
cfp->cf_lrev = ent->ce_rev;
if (ent->ce_type == CVS_ENT_FILE) {
- if (ent->ce_tag[0] != '\0') {
- cfp->cf_tag = strdup(ent->ce_tag);
- if (cfp->cf_tag == NULL) {
- cvs_file_free(cfp);
- return (NULL);
- }
- }
+ if (ent->ce_tag[0] != '\0')
+ cfp->cf_tag = xstrdup(ent->ce_tag);
- if (ent->ce_opts[0] != '\0') {
- cfp->cf_opts = strdup(ent->ce_opts);
- if (cfp->cf_opts == NULL) {
- cvs_file_free(cfp);
- return (NULL);
- }
- }
+ if (ent->ce_opts[0] != '\0')
+ cfp->cf_opts = xstrdup(ent->ce_opts);
}
}
@@ -1332,26 +1275,18 @@ cvs_file_lget(const char *path, int flags, CVSFILE *parent, CVSENTRIES *pent,
cfp->cf_mode = 0644;
cfp->cf_cvstat = CVS_FST_LOST;
- if ((c = strdup(cfp->cf_dir)) == NULL) {
- cvs_file_free(cfp);
- return (NULL);
- }
-
- free(cfp->cf_dir);
+ c = xstrdup(cfp->cf_dir);
+ xfree(cfp->cf_dir);
if (strcmp(c, root->cr_dir)) {
c += strlen(root->cr_dir) + 1;
- if ((cfp->cf_dir = strdup(c)) == NULL) {
- cvs_file_free(cfp);
- return (NULL);
- }
-
+ cfp->cf_dir = xstrdup(c);
c -= strlen(root->cr_dir) + 1;
} else {
cfp->cf_dir = NULL;
}
- free(c);
+ xfree(c);
}
if ((cfp->cf_repo != NULL) && (cfp->cf_type == DT_DIR) &&
diff --git a/usr.bin/cvs/hist.c b/usr.bin/cvs/hist.c
index 8e9e1909221..475e4471f3a 100644
--- a/usr.bin/cvs/hist.c
+++ b/usr.bin/cvs/hist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hist.c,v 1.11 2005/09/05 19:45:42 xsa Exp $ */
+/* $OpenBSD: hist.c,v 1.12 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -54,20 +54,10 @@ cvs_hist_open(const char *path)
{
CVSHIST *histp;
- histp = (CVSHIST *)malloc(sizeof(*histp));
- if (histp == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate CVS history");
- return (NULL);
- }
+ histp = (CVSHIST *)xmalloc(sizeof(*histp));
memset(histp, 0, sizeof(*histp));
- histp->chf_buf = (char *)malloc((size_t)CVS_HIST_BUFSIZE);
- if (histp->chf_buf == NULL) {
- cvs_log(LP_ERRNO,
- "failed to allocate CVS history parse buffer");
- free(histp);
- return (NULL);
- }
+ histp->chf_buf = (char *)xmalloc((size_t)CVS_HIST_BUFSIZE);
histp->chf_blen = CVS_HIST_BUFSIZE;
histp->chf_off = 0;
@@ -82,8 +72,8 @@ cvs_hist_open(const char *path)
cvs_log(LP_ERRNO,
"failed to open CVS history file `%s'", path);
cvs_nolog = 1;
- free(histp->chf_buf);
- free(histp);
+ xfree(histp->chf_buf);
+ xfree(histp);
return (NULL);
}
@@ -103,8 +93,8 @@ cvs_hist_close(CVSHIST *histp)
{
if (histp->chf_fd >= 0)
(void)close(histp->chf_fd);
- free(histp->chf_buf);
- free(histp);
+ xfree(histp->chf_buf);
+ xfree(histp);
}
diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c
index 6e3c6a80c4e..87b73444b09 100644
--- a/usr.bin/cvs/import.c
+++ b/usr.bin/cvs/import.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: import.c,v 1.30 2005/12/03 01:02:09 joris Exp $ */
+/* $OpenBSD: import.c,v 1.31 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Joris Vink <joris@openbsd.org>
* All rights reserved.
@@ -100,11 +100,7 @@ cvs_import_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
case 'k':
break;
case 'm':
- cvs_msg = strdup(optarg);
- if (cvs_msg == NULL) {
- cvs_log(LP_ERRNO, "failed to copy message");
- return (CVS_EX_DATA);
- }
+ cvs_msg = xstrdup(optarg);
break;
default:
return (CVS_EX_USAGE);
diff --git a/usr.bin/cvs/log.c b/usr.bin/cvs/log.c
index 2b1dcac08c5..86298ff9585 100644
--- a/usr.bin/cvs/log.c
+++ b/usr.bin/cvs/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.27 2005/10/09 23:59:17 joris Exp $ */
+/* $OpenBSD: log.c,v 1.28 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -339,7 +339,7 @@ cvs_printf(const char *fmt, ...)
send_m = 1;
dp = sp + 1;
}
- free(nstr);
+ xfree(nstr);
}
} else
#endif
diff --git a/usr.bin/cvs/logmsg.c b/usr.bin/cvs/logmsg.c
index 7a919b91787..1180ede690a 100644
--- a/usr.bin/cvs/logmsg.c
+++ b/usr.bin/cvs/logmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logmsg.c,v 1.21 2005/08/14 19:49:18 xsa Exp $ */
+/* $OpenBSD: logmsg.c,v 1.22 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -287,7 +287,7 @@ cvs_logmsg_get(const char *dir, struct cvs_flist *added,
break;
} else if ((buf[0] == '\n') || (buf[0] == 'c')) {
/* empty message */
- msg = strdup("");
+ msg = xstrdup("");
break;
} else if (buf[0] == 'e')
continue;
diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c
index 42f339b5704..329fc557884 100644
--- a/usr.bin/cvs/proto.c
+++ b/usr.bin/cvs/proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.c,v 1.79 2005/10/17 16:16:00 moritz Exp $ */
+/* $OpenBSD: proto.c,v 1.80 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -313,10 +313,10 @@ cvs_connect(struct cvsroot *root)
if (cvs_sendreq(root, CVS_REQ_VALIDRESP, vresp) < 0) {
cvs_log(LP_ERR, "failed to get valid responses");
- free(vresp);
+ xfree(vresp);
return (-1);
}
- free(vresp);
+ xfree(vresp);
if (cvs_sendreq(root, CVS_REQ_VALIDREQ, NULL) < 0) {
cvs_log(LP_ERR, "failed to get valid requests from server");
@@ -459,12 +459,7 @@ cvs_req_getvalid(void)
}
len = cvs_buf_len(buf);
- vrstr = (char *)malloc(len);
- if (vrstr == NULL) {
- cvs_buf_free(buf);
- return (NULL);
- }
-
+ vrstr = (char *)xmalloc(len);
cvs_buf_copy(buf, (size_t)0, vrstr, len);
cvs_buf_free(buf);
@@ -542,12 +537,7 @@ cvs_resp_getvalid(void)
}
len = cvs_buf_len(buf);
- vrstr = (char *)malloc(len);
- if (vrstr == NULL) {
- cvs_buf_free(buf);
- return (NULL);
- }
-
+ vrstr = (char *)xmalloc(len);
cvs_buf_copy(buf, (size_t)0, vrstr, len);
cvs_buf_free(buf);
@@ -1100,15 +1090,13 @@ cvs_initlog(void)
if (env == NULL)
return (0);
- if ((envdup = strdup(env)) == NULL)
- return (-1);
-
+ envdup = xstrdup(env);
if ((s = strchr(envdup, '%')) != NULL)
*s = '\0';
strlcpy(buf, env, sizeof(buf));
strlcpy(rpath, envdup, sizeof(rpath));
- free(envdup);
+ xfree(envdup);
s = buf;
while ((s = strchr(s, '%')) != NULL) {
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index d890e732f21..3b5501d3d06 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.109 2005/12/08 18:56:10 joris Exp $ */
+/* $OpenBSD: rcs.c,v 1.110 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -331,20 +331,10 @@ rcs_open(const char *path, int flags, ...)
return (NULL);
}
- if ((rfp = (RCSFILE *)malloc(sizeof(*rfp))) == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate RCS file structure");
- rcs_errno = RCS_ERR_ERRNO;
- return (NULL);
- }
+ rfp = (RCSFILE *)xmalloc(sizeof(*rfp));
memset(rfp, 0, sizeof(*rfp));
- if ((rfp->rf_path = strdup(path)) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to duplicate RCS file path");
- free(rfp);
- return (NULL);
- }
-
+ rfp->rf_path = xstrdup(path);
rfp->rf_ref = 1;
rfp->rf_flags = flags | RCS_SLOCK;
rfp->rf_mode = fmode;
@@ -367,11 +357,7 @@ rcs_open(const char *path, int flags, ...)
return (NULL);
}
- rdp->rd_locker = strdup(lkr->rl_name);
- if (rdp->rd_locker == NULL) {
- rcs_close(rfp);
- return (NULL);
- }
+ rdp->rd_locker = xstrdup(lkr->rl_name);
}
return (rfp);
@@ -407,24 +393,24 @@ rcs_close(RCSFILE *rfp)
while (!TAILQ_EMPTY(&(rfp->rf_access))) {
rap = TAILQ_FIRST(&(rfp->rf_access));
TAILQ_REMOVE(&(rfp->rf_access), rap, ra_list);
- free(rap->ra_name);
- free(rap);
+ xfree(rap->ra_name);
+ xfree(rap);
}
while (!TAILQ_EMPTY(&(rfp->rf_symbols))) {
rsp = TAILQ_FIRST(&(rfp->rf_symbols));
TAILQ_REMOVE(&(rfp->rf_symbols), rsp, rs_list);
rcsnum_free(rsp->rs_num);
- free(rsp->rs_name);
- free(rsp);
+ xfree(rsp->rs_name);
+ xfree(rsp);
}
while (!TAILQ_EMPTY(&(rfp->rf_locks))) {
rlp = TAILQ_FIRST(&(rfp->rf_locks));
TAILQ_REMOVE(&(rfp->rf_locks), rlp, rl_list);
rcsnum_free(rlp->rl_num);
- free(rlp->rl_name);
- free(rlp);
+ xfree(rlp->rl_name);
+ xfree(rlp);
}
if (rfp->rf_head != NULL)
@@ -433,14 +419,14 @@ rcs_close(RCSFILE *rfp)
rcsnum_free(rfp->rf_branch);
if (rfp->rf_path != NULL)
- free(rfp->rf_path);
+ xfree(rfp->rf_path);
if (rfp->rf_comment != NULL)
- free(rfp->rf_comment);
+ xfree(rfp->rf_comment);
if (rfp->rf_expand != NULL)
- free(rfp->rf_expand);
+ xfree(rfp->rf_expand);
if (rfp->rf_desc != NULL)
- free(rfp->rf_desc);
- free(rfp);
+ xfree(rfp->rf_desc);
+ xfree(rfp);
}
/*
@@ -616,13 +602,7 @@ rcs_write(RCSFILE *rfp)
return (-1);
}
- if ((bp = malloc(MAXBSIZE)) == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate memory");
- close(from_fd);
- close(to_fd);
- return (-1);
- }
-
+ bp = xmalloc(MAXBSIZE);
while ((nread = read(from_fd, bp, MAXBSIZE)) > 0) {
if (write(to_fd, bp, nread) != nread)
goto err;
@@ -635,13 +615,13 @@ err: if (unlink(rfp->rf_path) == -1)
rfp->rf_path);
close(from_fd);
close(to_fd);
- free(bp);
+ xfree(bp);
return (-1);
}
close(from_fd);
close(to_fd);
- free(bp);
+ xfree(bp);
if (unlink(fn) == -1) {
cvs_log(LP_ERRNO,
@@ -758,20 +738,8 @@ rcs_access_add(RCSFILE *file, const char *login)
}
}
- ap = (struct rcs_access *)malloc(sizeof(*ap));
- if (ap == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS access entry");
- return (-1);
- }
-
- ap->ra_name = strdup(login);
- if (ap->ra_name == NULL) {
- cvs_log(LP_ERRNO, "failed to duplicate user name");
- free(ap);
- return (-1);
- }
-
+ ap = (struct rcs_access *)xmalloc(sizeof(*ap));
+ ap->ra_name = xstrdup(login);
TAILQ_INSERT_TAIL(&(file->rf_access), ap, ra_list);
/* not synced anymore */
@@ -801,8 +769,8 @@ rcs_access_remove(RCSFILE *file, const char *login)
}
TAILQ_REMOVE(&(file->rf_access), ap, ra_list);
- free(ap->ra_name);
- free(ap);
+ xfree(ap->ra_name);
+ xfree(ap);
/* not synced anymore */
file->rf_flags &= ~RCS_SYNCED;
@@ -834,22 +802,11 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum)
}
}
- if ((symp = (struct rcs_sym *)malloc(sizeof(*symp))) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS symbol");
- return (-1);
- }
-
- if ((symp->rs_name = strdup(sym)) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to duplicate symbol");
- free(symp);
- return (-1);
- }
-
+ symp = (struct rcs_sym *)xmalloc(sizeof(*symp));
+ symp->rs_name = xstrdup(sym);
if ((symp->rs_num = rcsnum_alloc()) == NULL) {
- free(symp->rs_name);
- free(symp);
+ xfree(symp->rs_name);
+ xfree(symp);
return (-1);
}
rcsnum_cpy(snum, symp->rs_num, 0);
@@ -889,9 +846,9 @@ rcs_sym_remove(RCSFILE *file, const char *sym)
}
TAILQ_REMOVE(&(file->rf_symbols), symp, rs_list);
- free(symp->rs_name);
+ xfree(symp->rs_name);
rcsnum_free(symp->rs_num);
- free(symp);
+ xfree(symp);
/* not synced anymore */
file->rf_flags &= ~RCS_SYNCED;
@@ -1016,22 +973,11 @@ rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev)
}
}
- if ((lkp = (struct rcs_lock *)malloc(sizeof(*lkp))) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS lock");
- return (-1);
- }
-
- lkp->rl_name = strdup(user);
- if (lkp->rl_name == NULL) {
- cvs_log(LP_ERRNO, "failed to duplicate user name");
- free(lkp);
- return (-1);
- }
-
+ lkp = (struct rcs_lock *)xmalloc(sizeof(*lkp));
+ lkp->rl_name = xstrdup(user);
if ((lkp->rl_num = rcsnum_alloc()) == NULL) {
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
return (-1);
}
rcsnum_cpy(rev, lkp->rl_num, 0);
@@ -1070,8 +1016,8 @@ rcs_lock_remove(RCSFILE *file, const char *user, RCSNUM *rev)
TAILQ_REMOVE(&(file->rf_locks), lkp, rl_list);
rcsnum_free(lkp->rl_num);
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
/* not synced anymore */
file->rf_flags &= ~RCS_SYNCED;
@@ -1100,11 +1046,9 @@ rcs_desc_set(RCSFILE *file, const char *desc)
{
char *tmp;
- if ((tmp = strdup(desc)) == NULL)
- return (-1);
-
+ tmp = xstrdup(desc);
if (file->rf_desc != NULL)
- free(file->rf_desc);
+ xfree(file->rf_desc);
file->rf_desc = tmp;
file->rf_flags &= ~RCS_SYNCED;
@@ -1157,11 +1101,9 @@ rcs_comment_set(RCSFILE *file, const char *comment)
{
char *tmp;
- if ((tmp = strdup(comment)) == NULL)
- return (-1);
-
+ tmp = xstrdup(comment);
if (file->rf_comment != NULL)
- free(file->rf_comment);
+ xfree(file->rf_comment);
file->rf_comment = tmp;
file->rf_flags &= ~RCS_SYNCED;
@@ -1344,7 +1286,7 @@ rcs_getrev(RCSFILE *rfp, RCSNUM *frev)
bp = cvs_buf_release(rbuf);
rbuf = cvs_patchfile((char *)bp, (char *)rdp->rd_text,
rcs_patch_lines);
- free(bp);
+ xfree(bp);
if (rbuf == NULL)
break;
} while (rcsnum_cmp(crev, rev, 0) != 0);
@@ -1381,7 +1323,7 @@ rcs_getrev(RCSFILE *rfp, RCSNUM *frev)
}
cvs_freelines(lines);
}
- free(bp);
+ xfree(bp);
}
return (dbuf);
@@ -1448,11 +1390,7 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date,
return (-1);
}
- if ((rdp = (struct rcs_delta *)malloc(sizeof(*rdp))) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- rcsnum_free(old);
- return (-1);
- }
+ rdp = (struct rcs_delta *)xmalloc(sizeof(*rdp));
memset(rdp, 0, sizeof(*rdp));
TAILQ_INIT(&(rdp->rd_branches));
@@ -1479,24 +1417,9 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date,
if (username == NULL)
username = pw->pw_name;
- if ((rdp->rd_author = strdup(username)) == NULL) {
- rcs_freedelta(rdp);
- rcsnum_free(old);
- return (-1);
- }
-
- if ((rdp->rd_state = strdup(RCS_STATE_EXP)) == NULL) {
- rcs_freedelta(rdp);
- rcsnum_free(old);
- return (-1);
- }
-
- if ((rdp->rd_log = strdup(msg)) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- rcs_freedelta(rdp);
- rcsnum_free(old);
- return (-1);
- }
+ rdp->rd_author = xstrdup(username);
+ rdp->rd_state = xstrdup(RCS_STATE_EXP);
+ rdp->rd_log = xstrdup(msg);
if (date != (time_t)(-1))
now = date;
@@ -1608,12 +1531,7 @@ rcs_kwexp_set(RCSFILE *file, int mode)
buf[i++] = 'l';
}
- if ((tmp = strdup(buf)) == NULL) {
- cvs_log(LP_ERRNO, "%s: failed to copy expansion mode",
- file->rf_path);
- return (-1);
- }
-
+ tmp = xstrdup(buf);
if (file->rf_expand != NULL)
free(file->rf_expand);
file->rf_expand = tmp;
@@ -1719,11 +1637,7 @@ rcs_parse(RCSFILE *rfp)
if (rfp->rf_flags & RCS_PARSED)
return (0);
- if ((pdp = (struct rcs_pdata *)malloc(sizeof(*pdp))) == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS parser data");
- return (-1);
- }
+ pdp = (struct rcs_pdata *)xmalloc(sizeof(*pdp));
memset(pdp, 0, sizeof(*pdp));
pdp->rp_lines = 0;
@@ -1737,13 +1651,7 @@ rcs_parse(RCSFILE *rfp)
return (-1);
}
- pdp->rp_buf = (char *)malloc((size_t)RCS_BUFSIZE);
- if (pdp->rp_buf == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS parser buffer");
- rcs_freepdata(pdp);
- return (-1);
- }
+ pdp->rp_buf = (char *)xmalloc((size_t)RCS_BUFSIZE);
pdp->rp_blen = RCS_BUFSIZE;
pdp->rp_bufend = pdp->rp_buf + pdp->rp_blen - 1;
@@ -1784,13 +1692,7 @@ rcs_parse(RCSFILE *rfp)
return (-1);
}
- rfp->rf_desc = strdup(RCS_TOKSTR(rfp));
- if (rfp->rf_desc == NULL) {
- cvs_log(LP_ERRNO, "failed to duplicate rcs token");
- rcs_freepdata(pdp);
- return (-1);
- }
-
+ rfp->rf_desc = xstrdup(RCS_TOKSTR(rfp));
for (;;) {
ret = rcs_parse_deltatext(rfp);
if (ret == 0)
@@ -1886,19 +1788,9 @@ rcs_parse_admin(RCSFILE *rfp)
rfp->rf_branch) < 0)
return (-1);
} else if (tok == RCS_TOK_COMMENT) {
- rfp->rf_comment = strdup(RCS_TOKSTR(rfp));
- if (rfp->rf_comment == NULL) {
- cvs_log(LP_ERRNO,
- "failed to duplicate rcs token");
- return (-1);
- }
+ rfp->rf_comment = xstrdup(RCS_TOKSTR(rfp));
} else if (tok == RCS_TOK_EXPAND) {
- rfp->rf_expand = strdup(RCS_TOKSTR(rfp));
- if (rfp->rf_expand == NULL) {
- cvs_log(LP_ERRNO,
- "failed to duplicate rcs token");
- return (-1);
- }
+ rfp->rf_expand = xstrdup(RCS_TOKSTR(rfp));
}
/* now get the expected semi-colon */
@@ -1953,12 +1845,7 @@ rcs_parse_delta(RCSFILE *rfp)
struct rcs_delta *rdp;
struct rcs_key *rk;
- rdp = (struct rcs_delta *)malloc(sizeof(*rdp));
- if (rdp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS delta structure");
- return (-1);
- }
+ rdp = (struct rcs_delta *)xmalloc(sizeof(*rdp));
memset(rdp, 0, sizeof(*rdp));
rdp->rd_num = rcsnum_alloc();
@@ -2044,15 +1931,8 @@ rcs_parse_delta(RCSFILE *rfp)
}
if (tokstr != NULL)
- free(tokstr);
- tokstr = strdup(RCS_TOKSTR(rfp));
- if (tokstr == NULL) {
- cvs_log(LP_ERRNO,
- "failed to duplicate rcs token");
- rcs_freedelta(rdp);
- return (-1);
- }
-
+ xfree(tokstr);
+ tokstr = xstrdup(RCS_TOKSTR(rfp));
/* now get the expected semi-colon */
ntok = rcs_gettok(rfp);
if (ntok != RCS_TOK_SCOLON) {
@@ -2060,14 +1940,14 @@ rcs_parse_delta(RCSFILE *rfp)
cvs_log(LP_ERR,
"missing semi-colon after RCS `%s' key",
rk->rk_str);
- free(tokstr);
+ xfree(tokstr);
rcs_freedelta(rdp);
return (-1);
}
if (tok == RCS_TOK_DATE) {
if ((datenum = rcsnum_parse(tokstr)) == NULL) {
- free(tokstr);
+ xfree(tokstr);
rcs_freedelta(rdp);
return (-1);
}
@@ -2078,7 +1958,7 @@ rcs_parse_delta(RCSFILE *rfp)
"fields",
(datenum->rn_len > 6) ? "too many" :
"missing");
- free(tokstr);
+ xfree(tokstr);
rcs_freedelta(rdp);
rcsnum_free(datenum);
return (-1);
@@ -2119,7 +1999,7 @@ rcs_parse_delta(RCSFILE *rfp)
}
if (tokstr != NULL)
- free(tokstr);
+ xfree(tokstr);
TAILQ_INSERT_TAIL(&(rfp->rf_delta), rdp, rd_list);
rfp->rf_ndelta++;
@@ -2186,12 +2066,7 @@ rcs_parse_deltatext(RCSFILE *rfp)
RCS_TOKSTR(rfp));
return (-1);
}
- rdp->rd_log = strdup(RCS_TOKSTR(rfp));
- if (rdp->rd_log == NULL) {
- cvs_log(LP_ERRNO, "failed to copy RCS deltatext log");
- return (-1);
- }
-
+ rdp->rd_log = xstrdup(RCS_TOKSTR(rfp));
tok = rcs_gettok(rfp);
if (tok != RCS_TOK_TEXT) {
rcs_errno = RCS_ERR_PARSE;
@@ -2208,11 +2083,7 @@ rcs_parse_deltatext(RCSFILE *rfp)
return (-1);
}
- rdp->rd_text = (u_char *)malloc(RCS_TOKLEN(rfp) + 1);
- if (rdp->rd_text == NULL) {
- cvs_log(LP_ERRNO, "failed to copy RCS delta text");
- return (-1);
- }
+ rdp->rd_text = (u_char *)xmalloc(RCS_TOKLEN(rfp) + 1);
strlcpy(rdp->rd_text, RCS_TOKSTR(rfp), (RCS_TOKLEN(rfp) + 1));
rdp->rd_tlen = RCS_TOKLEN(rfp);
@@ -2269,24 +2140,13 @@ rcs_parse_symbols(RCSFILE *rfp)
return (-1);
}
- symp = (struct rcs_sym *)malloc(sizeof(*symp));
- if (symp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS symbol");
- return (-1);
- }
- symp->rs_name = strdup(RCS_TOKSTR(rfp));
- if (symp->rs_name == NULL) {
- cvs_log(LP_ERRNO, "failed to duplicate rcs token");
- free(symp);
- return (-1);
- }
-
+ symp = (struct rcs_sym *)xmalloc(sizeof(*symp));
+ symp->rs_name = xstrdup(RCS_TOKSTR(rfp));
symp->rs_num = rcsnum_alloc();
if (symp->rs_num == NULL) {
cvs_log(LP_ERRNO, "failed to allocate rcsnum info");
- free(symp->rs_name);
- free(symp);
+ xfree(symp->rs_name);
+ xfree(symp);
return (-1);
}
@@ -2296,8 +2156,8 @@ rcs_parse_symbols(RCSFILE *rfp)
cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
RCS_TOKSTR(rfp));
rcsnum_free(symp->rs_num);
- free(symp->rs_name);
- free(symp);
+ xfree(symp->rs_name);
+ xfree(symp);
return (-1);
}
@@ -2307,8 +2167,8 @@ rcs_parse_symbols(RCSFILE *rfp)
cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
RCS_TOKSTR(rfp));
rcsnum_free(symp->rs_num);
- free(symp->rs_name);
- free(symp);
+ xfree(symp->rs_name);
+ xfree(symp);
return (-1);
}
@@ -2316,8 +2176,8 @@ rcs_parse_symbols(RCSFILE *rfp)
cvs_log(LP_ERR, "failed to parse RCS NUM `%s'",
RCS_TOKSTR(rfp));
rcsnum_free(symp->rs_num);
- free(symp->rs_name);
- free(symp);
+ xfree(symp->rs_name);
+ xfree(symp);
return (-1);
}
@@ -2351,22 +2211,12 @@ rcs_parse_locks(RCSFILE *rfp)
return (-1);
}
- lkp = (struct rcs_lock *)malloc(sizeof(*lkp));
- if (lkp == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate RCS lock");
- return (-1);
- }
-
- if ((lkp->rl_name = strdup(RCS_TOKSTR(rfp))) == NULL) {
- cvs_log(LP_ERR, "failed to save locking user");
- free(lkp);
- return (-1);
- }
-
+ lkp = (struct rcs_lock *)xmalloc(sizeof(*lkp));
+ lkp->rl_name = xstrdup(RCS_TOKSTR(rfp));
lkp->rl_num = rcsnum_alloc();
if (lkp->rl_num == NULL) {
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
return (-1);
}
@@ -2376,8 +2226,8 @@ rcs_parse_locks(RCSFILE *rfp)
cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
RCS_TOKSTR(rfp));
rcsnum_free(lkp->rl_num);
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
return (-1);
}
@@ -2387,8 +2237,8 @@ rcs_parse_locks(RCSFILE *rfp)
cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
RCS_TOKSTR(rfp));
rcsnum_free(lkp->rl_num);
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
return (-1);
}
@@ -2396,8 +2246,8 @@ rcs_parse_locks(RCSFILE *rfp)
cvs_log(LP_ERR, "failed to parse RCS NUM `%s'",
RCS_TOKSTR(rfp));
rcsnum_free(lkp->rl_num);
- free(lkp->rl_name);
- free(lkp);
+ xfree(lkp->rl_name);
+ xfree(lkp);
return (-1);
}
@@ -2448,15 +2298,10 @@ rcs_parse_branches(RCSFILE *rfp, struct rcs_delta *rdp)
return (-1);
}
- brp = (struct rcs_branch *)malloc(sizeof(*brp));
- if (brp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- cvs_log(LP_ERRNO, "failed to allocate RCS branch");
- return (-1);
- }
+ brp = (struct rcs_branch *)xmalloc(sizeof(*brp));
brp->rb_num = rcsnum_parse(RCS_TOKSTR(rfp));
if (brp->rb_num == NULL) {
- free(brp);
+ xfree(brp);
return (-1);
}
@@ -2483,20 +2328,20 @@ rcs_freedelta(struct rcs_delta *rdp)
rcsnum_free(rdp->rd_next);
if (rdp->rd_author != NULL)
- free(rdp->rd_author);
+ xfree(rdp->rd_author);
if (rdp->rd_locker != NULL)
- free(rdp->rd_locker);
+ xfree(rdp->rd_locker);
if (rdp->rd_state != NULL)
- free(rdp->rd_state);
+ xfree(rdp->rd_state);
if (rdp->rd_log != NULL)
- free(rdp->rd_log);
+ xfree(rdp->rd_log);
if (rdp->rd_text != NULL)
- free(rdp->rd_text);
+ xfree(rdp->rd_text);
while ((rb = TAILQ_FIRST(&(rdp->rd_branches))) != NULL) {
TAILQ_REMOVE(&(rdp->rd_branches), rb, rb_list);
rcsnum_free(rb->rb_num);
- free(rb);
+ xfree(rb);
}
while ((crdp = TAILQ_FIRST(&(rdp->rd_snodes))) != NULL) {
@@ -2504,7 +2349,7 @@ rcs_freedelta(struct rcs_delta *rdp)
rcs_freedelta(crdp);
}
- free(rdp);
+ xfree(rdp);
}
/*
@@ -2518,8 +2363,8 @@ rcs_freepdata(struct rcs_pdata *pd)
if (pd->rp_file != NULL)
(void)fclose(pd->rp_file);
if (pd->rp_buf != NULL)
- free(pd->rp_buf);
- free(pd);
+ xfree(pd->rp_buf);
+ xfree(pd);
}
/*
@@ -2901,13 +2746,11 @@ rcs_deltatext_set(RCSFILE *rfp, RCSNUM *rev, const char *dtext)
return (-1);
if (rdp->rd_text != NULL)
- free(rdp->rd_text);
+ xfree(rdp->rd_text);
len = strlen(dtext);
if (len != 0) {
- if ((rdp->rd_text = (u_char *)malloc(len)) == NULL)
- return (-1);
-
+ rdp->rd_text = (u_char *)xmalloc(len);
rdp->rd_tlen = len - 1;
strlcpy(rdp->rd_text, dtext, len);
} else {
@@ -2935,11 +2778,9 @@ rcs_rev_setlog(RCSFILE *rfp, RCSNUM *rev, const char *logtext)
return (-1);
if (rdp->rd_log != NULL)
- free(rdp->rd_log);
-
- if ((rdp->rd_log = strdup(logtext)) == NULL)
- return (-1);
+ xfree(rdp->rd_log);
+ rdp->rd_log = xstrdup(logtext);
rfp->rf_flags &= ~RCS_SYNCED;
return (0);
}
@@ -2977,10 +2818,9 @@ rcs_state_set(RCSFILE *rfp, RCSNUM *rev, const char *state)
return (-1);
if (rdp->rd_state != NULL)
- free(rdp->rd_state);
+ xfree(rdp->rd_state);
- if ((rdp->rd_state = strdup(state)) == NULL)
- return (-1);
+ rdp->rd_state = xstrdup(state);
rfp->rf_flags &= ~RCS_SYNCED;
@@ -3253,7 +3093,7 @@ out:
if (bp != NULL)
cvs_buf_free(bp);
if (content != NULL)
- free(content);
+ xfree(content);
return (ret);
}
diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c
index 5bcd5cac6fd..0780334aeb1 100644
--- a/usr.bin/cvs/rcsnum.c
+++ b/usr.bin/cvs/rcsnum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsnum.c,v 1.17 2005/10/10 13:06:24 joris Exp $ */
+/* $OpenBSD: rcsnum.c,v 1.18 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -50,11 +50,7 @@ rcsnum_alloc(void)
{
RCSNUM *rnp;
- rnp = (RCSNUM *)malloc(sizeof(*rnp));
- if (rnp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- return (NULL);
- }
+ rnp = (RCSNUM *)xmalloc(sizeof(*rnp));
rnp->rn_len = 0;
rnp->rn_id = NULL;
@@ -94,8 +90,8 @@ void
rcsnum_free(RCSNUM *rn)
{
if (rn->rn_id != NULL)
- free(rn->rn_id);
- free(rn);
+ xfree(rn->rn_id);
+ xfree(rn);
}
/*
@@ -145,12 +141,7 @@ rcsnum_cpy(const RCSNUM *nsrc, RCSNUM *ndst, u_int depth)
len = depth;
sz = len * sizeof(u_int16_t);
- tmp = realloc(ndst->rn_id, sz);
- if (tmp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- return (-1);
- }
-
+ tmp = xrealloc(ndst->rn_id, sz);
ndst->rn_id = (u_int16_t *)tmp;
ndst->rn_len = len;
memcpy(ndst->rn_id, nsrc->rn_id, sz);
@@ -210,13 +201,8 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump)
void *tmp;
char *s;
- if (nump->rn_id == NULL) {
- nump->rn_id = (u_int16_t *)malloc(sizeof(u_int16_t));
- if (nump->rn_id == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- return (-1);
- }
- }
+ if (nump->rn_id == NULL)
+ nump->rn_id = (u_int16_t *)xmalloc(sizeof(u_int16_t));
nump->rn_len = 0;
nump->rn_id[0] = 0;
@@ -232,10 +218,8 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump)
}
nump->rn_len++;
- tmp = realloc(nump->rn_id,
+ tmp = xrealloc(nump->rn_id,
(nump->rn_len + 1) * sizeof(u_int16_t));
- if (tmp == NULL)
- goto rcsnum_aton_failed;
nump->rn_id = (u_int16_t *)tmp;
nump->rn_id[nump->rn_len] = 0;
continue;
@@ -306,7 +290,7 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump)
rcsnum_aton_failed:
nump->rn_len = 0;
- free(nump->rn_id);
+ xfree(nump->rn_id);
nump->rn_id = NULL;
return (-1);
}
@@ -401,12 +385,7 @@ rcsnum_setsize(RCSNUM *num, u_int len)
{
void *tmp;
- tmp = realloc(num->rn_id, len * sizeof(u_int16_t));
- if (tmp == NULL) {
- rcs_errno = RCS_ERR_ERRNO;
- return (-1);
- }
-
+ tmp = xrealloc(num->rn_id, len * sizeof(u_int16_t));
num->rn_id = (u_int16_t *)tmp;
num->rn_len = len;
return (0);
diff --git a/usr.bin/cvs/req.c b/usr.bin/cvs/req.c
index 965982f7fa8..749143dfd04 100644
--- a/usr.bin/cvs/req.c
+++ b/usr.bin/cvs/req.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: req.c,v 1.33 2005/12/03 20:27:35 joris Exp $ */
+/* $OpenBSD: req.c,v 1.34 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -213,7 +213,7 @@ cvs_req_root(int reqid, char *line)
return (-1);
}
- cvs_req_rootpath = strdup(line);
+ cvs_req_rootpath = xstrdup(line);
if (cvs_req_rootpath == NULL) {
cvs_log(LP_ERRNO, "failed to copy Root path");
return (-1);
@@ -280,9 +280,9 @@ cvs_req_directory(int reqid, char *line)
STRIP_SLASH(rdir);
if (cvs_req_currentdir != NULL)
- free(cvs_req_currentdir);
+ xfree(cvs_req_currentdir);
- cvs_req_currentdir = strdup(rdir);
+ cvs_req_currentdir = xstrdup(rdir);
if (cvs_req_currentdir == NULL) {
cvs_log(LP_ERR, "failed to duplicate directory");
return (-1);
@@ -309,7 +309,7 @@ cvs_req_directory(int reqid, char *line)
} else
s = cvs_req_currentdir;
- if ((repo = strdup(s)) == NULL) {
+ if ((repo = xstrdup(s)) == NULL) {
cvs_log(LP_ERR, "failed to save repository path");
return (-1);
}
@@ -322,7 +322,7 @@ cvs_req_directory(int reqid, char *line)
s = repo + strlen(repo) - strlen(line) - 1;
if (*s != '/') {
cvs_log(LP_ERR, "malformed directory");
- free(repo);
+ xfree(repo);
return (-1);
}
@@ -337,9 +337,9 @@ cvs_req_directory(int reqid, char *line)
if ((p = strchr(repo, '/')) != NULL)
*p = '\0';
- if ((cvs_req_modulename = strdup(repo)) == NULL) {
+ if ((cvs_req_modulename = xstrdup(repo)) == NULL) {
cvs_log(LP_ERR, "failed to save modulename");
- free(repo);
+ xfree(repo);
return (-1);
}
@@ -353,7 +353,7 @@ cvs_req_directory(int reqid, char *line)
if (cvs_mkadmin(cvs_server_tmpdir, cvs_rootstr, repo,
NULL, NULL, 0) < 0) {
cvs_log(LP_ERR, "failed to create admin files");
- free(repo);
+ xfree(repo);
return (-1);
}
}
@@ -362,7 +362,7 @@ cvs_req_directory(int reqid, char *line)
* create the directory plus the administrative files.
*/
if (cvs_create_dir(line, 1, cvs_rootstr, repo) < 0) {
- free(repo);
+ xfree(repo);
return (-1);
}
@@ -375,11 +375,11 @@ cvs_req_directory(int reqid, char *line)
cvs_req_entf = cvs_ent_open(".", O_RDWR);
if (cvs_req_entf == NULL) {
cvs_log(LP_ERR, "failed to open Entry file for %s", line);
- free(repo);
+ xfree(repo);
return (-1);
}
- free(repo);
+ xfree(repo);
return (0);
}
@@ -513,7 +513,7 @@ cvs_req_set(int reqid, char *line)
{
char *cp, *lp;
- if ((lp = strdup(line)) == NULL) {
+ if ((lp = xstrdup(line)) == NULL) {
cvs_log(LP_ERRNO, "failed to copy Set argument");
return (-1);
}
@@ -521,17 +521,17 @@ cvs_req_set(int reqid, char *line)
if ((cp = strchr(lp, '=')) == NULL) {
cvs_log(LP_ERR, "error in Set request "
"(no = in variable assignment)");
- free(lp);
+ xfree(lp);
return (-1);
}
*(cp++) = '\0';
if (cvs_var_set(lp, cp) < 0) {
- free(lp);
+ xfree(lp);
return (-1);
}
- free(lp);
+ xfree(lp);
return (0);
}
@@ -548,7 +548,7 @@ cvs_req_argument(int reqid, char *line)
}
if (reqid == CVS_REQ_ARGUMENT) {
- cvs_req_args[cvs_req_nargs] = strdup(line);
+ cvs_req_args[cvs_req_nargs] = xstrdup(line);
if (cvs_req_args[cvs_req_nargs] == NULL) {
cvs_log(LP_ERRNO, "failed to copy argument");
return (-1);
@@ -565,7 +565,7 @@ cvs_req_argument(int reqid, char *line)
"failed to append to argument");
return (-1);
}
- free(cvs_req_args[cvs_req_nargs - 1]);
+ xfree(cvs_req_args[cvs_req_nargs - 1]);
cvs_req_args[cvs_req_nargs - 1] = nap;
}
}
diff --git a/usr.bin/cvs/resp.c b/usr.bin/cvs/resp.c
index af9c683c929..713347d12ed 100644
--- a/usr.bin/cvs/resp.c
+++ b/usr.bin/cvs/resp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resp.c,v 1.63 2005/12/03 01:02:09 joris Exp $ */
+/* $OpenBSD: resp.c,v 1.64 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -228,7 +228,7 @@ cvs_resp_m(struct cvsroot *root, int type, char *line)
* remote server's version string.
*/
cvs_version_sent = 0;
- root->cr_version = strdup(line);
+ root->cr_version = xstrdup(line);
return (0);
}
stream = stdout;
@@ -243,9 +243,7 @@ cvs_resp_m(struct cvsroot *root, int type, char *line)
"MT scope stack has reached max depth");
return (-1);
}
- cvs_mt_stack[cvs_mtstk_depth] = strdup(line + 1);
- if (cvs_mt_stack[cvs_mtstk_depth] == NULL)
- return (-1);
+ cvs_mt_stack[cvs_mtstk_depth] = xstrdup(line + 1);
cvs_mtstk_depth++;
} else if (*line == '-') {
if (cvs_mtstk_depth == 0) {
@@ -256,7 +254,7 @@ cvs_resp_m(struct cvsroot *root, int type, char *line)
cvs_log(LP_ERR, "mismatch in MT scope stack");
return (-1);
}
- free(cvs_mt_stack[cvs_mtstk_depth--]);
+ xfree(cvs_mt_stack[cvs_mtstk_depth--]);
} else {
if (strcmp(line, "newline") == 0)
putc('\n', stdout);
@@ -550,14 +548,10 @@ cvs_resp_cksum(struct cvsroot *root, int type, char *line)
{
if (cvs_fcksum != NULL) {
cvs_log(LP_WARN, "unused checksum");
- free(cvs_fcksum);
+ xfree(cvs_fcksum);
}
- cvs_fcksum = strdup(line);
- if (cvs_fcksum == NULL) {
- cvs_log(LP_ERRNO, "failed to copy checksum string");
- return (-1);
- }
+ cvs_fcksum = xstrdup(line);
return (0);
}
@@ -716,7 +710,7 @@ cvs_resp_updated(struct cvsroot *root, int type, char *line)
ret = -1;
}
- free(cvs_fcksum);
+ xfree(cvs_fcksum);
cvs_fcksum = NULL;
}
@@ -854,7 +848,7 @@ cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
(void)unlink(file);
}
- free(cvs_fcksum);
+ xfree(cvs_fcksum);
cvs_fcksum = NULL;
}
diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c
index 0b3505cf0cd..0feff924e95 100644
--- a/usr.bin/cvs/root.c
+++ b/usr.bin/cvs/root.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: root.c,v 1.25 2005/09/11 14:16:48 joris Exp $ */
+/* $OpenBSD: root.c,v 1.26 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -98,11 +98,7 @@ cvsroot_parse(const char *str)
}
}
- root = (struct cvsroot *)malloc(sizeof(*root));
- if (root == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate CVS root data");
- return (NULL);
- }
+ root = (struct cvsroot *)xmalloc(sizeof(*root));
memset(root, 0, sizeof(*root));
root->cr_ref = 1;
root->cr_method = CVS_METHOD_NONE;
@@ -112,17 +108,8 @@ cvsroot_parse(const char *str)
CVS_SETVR(root, CVS_REQ_VALIDREQ);
CVS_SETVR(root, CVS_REQ_VALIDRESP);
- root->cr_str = strdup(str);
- if (root->cr_str == NULL) {
- free(root);
- return (NULL);
- }
- root->cr_buf = strdup(str);
- if (root->cr_buf == NULL) {
- cvs_log(LP_ERRNO, "failed to copy CVS root");
- cvsroot_free(root);
- return (NULL);
- }
+ root->cr_str = xstrdup(str);
+ root->cr_buf = xstrdup(str);
sp = root->cr_buf;
cp = root->cr_buf;
@@ -246,12 +233,12 @@ static void
cvsroot_free(struct cvsroot *root)
{
if (root->cr_str != NULL)
- free(root->cr_str);
+ xfree(root->cr_str);
if (root->cr_buf != NULL)
- free(root->cr_buf);
+ xfree(root->cr_buf);
if (root->cr_version != NULL)
- free(root->cr_version);
- free(root);
+ xfree(root->cr_version);
+ xfree(root);
}
/*
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index 30189cc4998..370a061a4df 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.58 2005/12/03 15:07:21 joris Exp $ */
+/* $OpenBSD: util.c,v 1.59 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -340,19 +340,14 @@ cvs_getargv(const char *line, char **argv, int argvlen)
break;
}
- argv[argc] = strdup(arg);
- if (argv[argc] == NULL) {
- cvs_log(LP_ERRNO, "failed to copy argument");
- err++;
- break;
- }
+ argv[argc] = xstrdup(arg);
argc++;
}
if (err != 0) {
/* ditch the argument vector */
for (i = 0; i < (u_int)argc; i++)
- free(argv[i]);
+ xfree(argv[i]);
argc = -1;
}
@@ -378,12 +373,7 @@ cvs_makeargv(const char *line, int *argc)
return (NULL);
size = (ret + 1) * sizeof(char *);
- copy = (char **)malloc(size);
- if (copy == NULL) {
- cvs_log(LP_ERRNO, "failed to allocate argument vector");
- cvs_freeargv(argv, ret);
- return (NULL);
- }
+ copy = (char **)xmalloc(size);
memset(copy, 0, size);
for (i = 0; i < ret; i++)
@@ -407,7 +397,7 @@ cvs_freeargv(char **argv, int argc)
for (i = 0; i < argc; i++)
if (argv[i] != NULL)
- free(argv[i]);
+ xfree(argv[i]);
}
@@ -644,22 +634,20 @@ cvs_create_dir(const char *path, int create_adm, char *root, char *repo)
return (-1);
}
- if ((s = strdup(path)) == NULL)
- return (-1);
-
+ s = xstrdup(path);
rpath[0] = '\0';
if (repo != NULL) {
if (strlcpy(rpath, repo, sizeof(rpath)) >= sizeof(rpath)) {
errno = ENAMETOOLONG;
cvs_log(LP_ERRNO, "%s", rpath);
- free(s);
+ xfree(s);
return (-1);
}
if (strlcat(rpath, "/", sizeof(rpath)) >= sizeof(rpath)) {
errno = ENAMETOOLONG;
cvs_log(LP_ERRNO, "%s", rpath);
- free(s);
+ xfree(s);
return (-1);
}
}
@@ -742,7 +730,7 @@ cvs_create_dir(const char *path, int create_adm, char *root, char *repo)
done:
if (entf != NULL)
cvs_ent_close(entf);
- free(s);
+ xfree(s);
return (ret);
}
@@ -904,15 +892,15 @@ cvs_parse_tagfile(char **tagp, char **datep, int *nbp)
switch (*linebuf) {
case 'T':
if (tagp != NULL)
- *tagp = strdup(linebuf);
+ *tagp = xstrdup(linebuf);
break;
case 'D':
if (datep != NULL)
- *datep = strdup(linebuf);
+ *datep = xstrdup(linebuf);
break;
case 'N':
if (tagp != NULL)
- *tagp = strdup(linebuf);
+ *tagp = xstrdup(linebuf);
if (nbp != NULL)
*nbp = 1;
break;
@@ -938,35 +926,18 @@ cvs_splitlines(const char *fcont)
struct cvs_lines *lines;
struct cvs_line *lp;
- lines = (struct cvs_lines *)malloc(sizeof(*lines));
- if (lines == NULL)
- return (NULL);
-
+ lines = (struct cvs_lines *)xmalloc(sizeof(*lines));
TAILQ_INIT(&(lines->l_lines));
lines->l_nblines = 0;
- lines->l_data = strdup(fcont);
- if (lines->l_data == NULL) {
- free(lines);
- return (NULL);
- }
-
- lp = (struct cvs_line *)malloc(sizeof(*lp));
- if (lp == NULL) {
- cvs_freelines(lines);
- return (NULL);
- }
+ lines->l_data = xstrdup(fcont);
+ lp = (struct cvs_line *)xmalloc(sizeof(*lp));
lp->l_line = NULL;
lp->l_lineno = 0;
TAILQ_INSERT_TAIL(&(lines->l_lines), lp, l_list);
for (dcp = lines->l_data; *dcp != '\0';) {
- lp = (struct cvs_line *)malloc(sizeof(*lp));
- if (lp == NULL) {
- cvs_freelines(lines);
- return (NULL);
- }
-
+ lp = (struct cvs_line *)xmalloc(sizeof(*lp));
lp->l_line = dcp;
lp->l_lineno = ++(lines->l_nblines);
TAILQ_INSERT_TAIL(&(lines->l_lines), lp, l_list);
@@ -987,11 +958,11 @@ cvs_freelines(struct cvs_lines *lines)
while ((lp = TAILQ_FIRST(&(lines->l_lines))) != NULL) {
TAILQ_REMOVE(&(lines->l_lines), lp, l_list);
- free(lp);
+ xfree(lp);
}
- free(lines->l_data);
- free(lines);
+ xfree(lines->l_data);
+ xfree(lines);
}
BUF *
diff --git a/usr.bin/cvs/watch.c b/usr.bin/cvs/watch.c
index 9d4601c40d0..781bad239e1 100644
--- a/usr.bin/cvs/watch.c
+++ b/usr.bin/cvs/watch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: watch.c,v 1.7 2005/10/17 16:16:00 moritz Exp $ */
+/* $OpenBSD: watch.c,v 1.8 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org>
* Copyright (c) 2005 Moritz Jodeit <moritz@openbsd.org>
@@ -123,10 +123,7 @@ cvs_watch_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg)
strcmp(optarg, "all") != 0 &&
strcmp(optarg, "none") != 0)
return (CVS_EX_USAGE);
- if ((aoptstr = strdup(optarg)) == NULL) {
- cvs_log(LP_ERRNO, "failed to copy action");
- return (CVS_EX_DATA);
- }
+ aoptstr = xstrdup(optarg);
break;
case 'l':
cmd->file_flags &= ~CF_RECURSE;
@@ -164,18 +161,18 @@ cvs_watch_pre_exec(struct cvsroot *root)
(cvs_sendarg(root, "unedit", 0) < 0) ||
(cvs_sendarg(root, "-a", 0) < 0) ||
(cvs_sendarg(root, "commit", 0) < 0)) {
- free(aoptstr);
+ xfree(aoptstr);
return (CVS_EX_PROTO);
}
} else {
if ((cvs_sendarg(root, "-a", 0) < 0) ||
(cvs_sendarg(root, aoptstr, 0) < 0)) {
- free(aoptstr);
+ xfree(aoptstr);
return (CVS_EX_PROTO);
}
}
}
- free(aoptstr);
+ xfree(aoptstr);
return (CVS_EX_OK);
}
diff --git a/usr.bin/cvs/xmalloc.c b/usr.bin/cvs/xmalloc.c
new file mode 100644
index 00000000000..b4009cdab70
--- /dev/null
+++ b/usr.bin/cvs/xmalloc.c
@@ -0,0 +1,67 @@
+/*
+ * Author: Tatu Ylonen <ylo@cs.hut.fi>
+ * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
+ * All rights reserved
+ * Versions of xmalloc and friends that check their results, and never return
+ * failure (they call fatal if they encounter an error).
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose. Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "cvs.h"
+
+void *
+xmalloc(size_t size)
+{
+ void *ptr;
+
+ if (size == 0)
+ fatal("xmalloc: zero size");
+ ptr = malloc(size);
+ if (ptr == NULL)
+ fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size);
+ return ptr;
+}
+
+void *
+xrealloc(void *ptr, size_t new_size)
+{
+ void *new_ptr;
+
+ if (new_size == 0)
+ fatal("xrealloc: zero size");
+ if (ptr == NULL)
+ new_ptr = xmalloc(new_size);
+ else
+ new_ptr = realloc(ptr, new_size);
+ if (new_ptr == NULL)
+ fatal("xrealloc: out of memory (new_size %lu bytes)", (u_long) new_size);
+ return new_ptr;
+}
+
+void
+xfree(void *ptr)
+{
+ if (ptr == NULL)
+ fatal("xfree: NULL pointer given as argument");
+ free(ptr);
+}
+
+char *
+xstrdup(const char *str)
+{
+ size_t len;
+ char *cp;
+
+ len = strlen(str) + 1;
+ cp = xmalloc(len);
+ strlcpy(cp, str, len);
+ return cp;
+}
diff --git a/usr.bin/cvs/xmalloc.h b/usr.bin/cvs/xmalloc.h
new file mode 100644
index 00000000000..b40cddd7fc5
--- /dev/null
+++ b/usr.bin/cvs/xmalloc.h
@@ -0,0 +1,27 @@
+/* $OpenBSD: xmalloc.h,v 1.1 2005/12/10 20:27:45 joris Exp $ */
+
+/*
+ * Author: Tatu Ylonen <ylo@cs.hut.fi>
+ * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
+ * All rights reserved
+ * Created: Mon Mar 20 22:09:17 1995 ylo
+ *
+ * Versions of xmalloc and friends that check their results, and never return
+ * failure (they call fatal if they encounter an error).
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose. Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ */
+
+#ifndef XMALLOC_H
+#define XMALLOC_H
+
+void *xmalloc(size_t);
+void *xrealloc(void *, size_t);
+void xfree(void *);
+char *xstrdup(const char *);
+
+#endif /* XMALLOC_H */
diff --git a/usr.bin/cvs/zlib.c b/usr.bin/cvs/zlib.c
index fb1bd30ee06..55d4d205a96 100644
--- a/usr.bin/cvs/zlib.c
+++ b/usr.bin/cvs/zlib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: zlib.c,v 1.3 2005/07/25 12:05:43 xsa Exp $ */
+/* $OpenBSD: zlib.c,v 1.4 2005/12/10 20:27:45 joris Exp $ */
/*
* Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -60,7 +60,7 @@ cvs_zlib_newctx(int level)
return (NULL);
}
- ctx = (CVSZCTX *)malloc(sizeof(*ctx));
+ ctx = (CVSZCTX *)xmalloc(sizeof(*ctx));
if (ctx == NULL) {
cvs_log(LP_ERRNO, "failed to allocate zlib context");
return (NULL);
@@ -79,7 +79,7 @@ cvs_zlib_newctx(int level)
if ((inflateInit(&(ctx->z_instrm)) != Z_OK) ||
(deflateInit(&(ctx->z_destrm), level) != Z_OK)) {
cvs_log(LP_ERR, "failed to initialize zlib streams");
- free(ctx);
+ xfree(ctx);
return (NULL);
}
@@ -98,7 +98,7 @@ cvs_zlib_free(CVSZCTX *ctx)
if (ctx != NULL) {
(void)inflateEnd(&(ctx->z_instrm));
(void)deflateEnd(&(ctx->z_destrm));
- free(ctx);
+ xfree(ctx);
}
}