summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-01-25 18:56:34 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-01-25 18:56:34 +0000
commitaabe59db15cb39a42f27d1427d74f2d201c72303 (patch)
treeaffbf2262bfb8b8bd0de9149dc39fcaea2339163 /usr.bin/cvs
parent3fae22de6760a857ade5af2f402f0a53e5575715 (diff)
use more stack allocations for fixed size buffers. ok xsa@ joris@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/add.c28
-rw-r--r--usr.bin/cvs/admin.c9
-rw-r--r--usr.bin/cvs/client.c35
-rw-r--r--usr.bin/cvs/commit.c21
-rw-r--r--usr.bin/cvs/edit.c21
-rw-r--r--usr.bin/cvs/entries.c23
-rw-r--r--usr.bin/cvs/file.c44
-rw-r--r--usr.bin/cvs/init.c8
-rw-r--r--usr.bin/cvs/remote.c12
-rw-r--r--usr.bin/cvs/repository.c10
-rw-r--r--usr.bin/cvs/server.c33
-rw-r--r--usr.bin/cvs/update.c6
12 files changed, 60 insertions, 190 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c
index 2606fd2b694..075d315f6ec 100644
--- a/usr.bin/cvs/add.c
+++ b/usr.bin/cvs/add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: add.c,v 1.69 2007/01/13 15:45:59 joris Exp $ */
+/* $OpenBSD: add.c,v 1.70 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -105,11 +105,10 @@ void
cvs_add_entry(struct cvs_file *cf)
{
int l;
- char *entry;
+ char entry[CVS_ENT_MAXLINELEN];
CVSENTRIES *entlist;
if (cf->file_type == CVS_DIR) {
- entry = xmalloc(CVS_ENT_MAXLINELEN);
l = snprintf(entry, CVS_ENT_MAXLINELEN,
"D/%s/////", cf->file_name);
if (l == -1 || l >= CVS_ENT_MAXLINELEN)
@@ -118,7 +117,6 @@ cvs_add_entry(struct cvs_file *cf)
entlist = cvs_ent_open(cf->file_wd);
cvs_ent_add(entlist, entry);
cvs_ent_close(entlist, ENT_SYNC);
- xfree(entry);
} else {
add_entry(cf);
}
@@ -154,11 +152,10 @@ add_directory(struct cvs_file *cf)
int l, added, nb;
struct stat st;
CVSENTRIES *entlist;
- char *date, *entry, msg[1024], *repo, *tag;
+ char *date, entry[MAXPATHLEN], msg[1024], repo[MAXPATHLEN], *tag, *p;
cvs_log(LP_TRACE, "add_directory(%s)", cf->file_path);
- entry = xmalloc(MAXPATHLEN);
l = snprintf(entry, MAXPATHLEN, "%s%s", cf->file_rpath, RCS_FILE_EXT);
if (l == -1 || l >= MAXPATHLEN)
fatal("cvs_add_local: overflow");
@@ -192,7 +189,6 @@ add_directory(struct cvs_file *cf)
fatal("add_directory: %s: %s", cf->file_path,
strerror(errno));
- repo = xmalloc(MAXPATHLEN);
cvs_get_repository_name(cf->file_wd, repo,
MAXPATHLEN);
@@ -203,14 +199,11 @@ add_directory(struct cvs_file *cf)
cvs_mkadmin(cf->file_path, current_cvsroot->cr_dir,
entry, tag, date, nb);
- xfree(repo);
- xfree(entry);
-
- entry = xmalloc(CVS_ENT_MAXLINELEN);
- l = snprintf(entry, CVS_ENT_MAXLINELEN,
+ p = xmalloc(CVS_ENT_MAXLINELEN);
+ l = snprintf(p, CVS_ENT_MAXLINELEN,
"D/%s/////", cf->file_name);
entlist = cvs_ent_open(cf->file_wd);
- cvs_ent_add(entlist, entry);
+ cvs_ent_add(entlist, p);
cvs_ent_close(entlist, ENT_SYNC);
}
}
@@ -327,14 +320,12 @@ add_entry(struct cvs_file *cf)
{
FILE *fp;
int l;
- char *entry, *path, revbuf[16], tbuf[32];
+ char entry[CVS_ENT_MAXLINELEN], path[MAXPATHLEN], revbuf[16], tbuf[32];
CVSENTRIES *entlist;
if (cvs_noexec == 1)
return;
- entry = xmalloc(CVS_ENT_MAXLINELEN);
-
if (cf->file_status == FILE_REMOVED) {
rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
@@ -349,8 +340,6 @@ add_entry(struct cvs_file *cf)
fatal("add_entry: truncation");
} else {
if (logmsg != NULL) {
- path = xmalloc(MAXPATHLEN);
-
l = snprintf(path, MAXPATHLEN, "%s/%s%s",
CVS_PATH_CVSDIR, cf->file_name, CVS_DESCR_FILE_EXT);
if (l == -1 || l >= MAXPATHLEN)
@@ -366,7 +355,6 @@ add_entry(struct cvs_file *cf)
path, strerror(errno));
}
(void)fclose(fp);
- xfree(path);
}
l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/0/Initial %s//",
@@ -378,6 +366,4 @@ add_entry(struct cvs_file *cf)
entlist = cvs_ent_open(cf->file_wd);
cvs_ent_add(entlist, entry);
cvs_ent_close(entlist, ENT_SYNC);
-
- xfree(entry);
}
diff --git a/usr.bin/cvs/admin.c b/usr.bin/cvs/admin.c
index 0254b0614e0..dfdc365dd80 100644
--- a/usr.bin/cvs/admin.c
+++ b/usr.bin/cvs/admin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: admin.c,v 1.45 2007/01/21 11:20:10 xsa Exp $ */
+/* $OpenBSD: admin.c,v 1.46 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
@@ -213,10 +213,8 @@ cvs_admin_local(struct cvs_file *cf)
struct cvs_file *ocf;
struct rcs_access *acp;
int ofd;
- char *d, *f, *fpath, *repo;
+ char *d, *f, fpath[MAXPATHLEN], repo[MAXPATHLEN];
- fpath = xmalloc(MAXPATHLEN);
- repo = xmalloc(MAXPATHLEN);
if ((f = basename(oldfilename)) == NULL)
fatal("cvs_admin_local: basename failed");
@@ -248,9 +246,6 @@ cvs_admin_local(struct cvs_file *cf)
(void)close(ofd);
cvs_file_free(ocf);
-
- xfree(fpath);
- xfree(repo);
}
if (alist != NULL) {
diff --git a/usr.bin/cvs/client.c b/usr.bin/cvs/client.c
index 02b49110118..ce88626126e 100644
--- a/usr.bin/cvs/client.c
+++ b/usr.bin/cvs/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.49 2007/01/18 16:45:52 joris Exp $ */
+/* $OpenBSD: client.c,v 1.50 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -365,21 +365,17 @@ cvs_client_senddir(const char *dir)
{
struct stat st;
int nb;
- char *d, *date, *fpath, *repo, *tag;
+ char *d, *date, fpath[MAXPATHLEN], repo[MAXPATHLEN], *tag;
d = NULL;
if (lastdir != NULL && !strcmp(dir, lastdir))
return;
- repo = xmalloc(MAXPATHLEN);
cvs_get_repository_path(dir, repo, MAXPATHLEN);
cvs_client_send_request("Directory %s\n%s", dir, repo);
- xfree(repo);
-
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(dir, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >=
MAXPATHLEN)
fatal("cvs_client_senddir: truncation");
@@ -387,8 +383,6 @@ cvs_client_senddir(const char *dir)
if (stat(fpath, &st) == 0 && (st.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)))
cvs_client_send_request("Static-directory");
- xfree(fpath);
-
d = xstrdup(dir);
cvs_parse_tagfile(d, &tag, &date, &nb);
@@ -619,7 +613,7 @@ cvs_client_updated(char *data)
struct cvs_ent *e;
const char *errstr;
struct timeval tv[2];
- char timebuf[32], *repo, *rpath, *entry, *mode;
+ char timebuf[32], repo[MAXPATHLEN], *rpath, *entry, *mode;
char revbuf[32], *len, *fpath, *wdir;
client_check_directory(data);
@@ -629,7 +623,6 @@ cvs_client_updated(char *data)
mode = cvs_remote_input();
len = cvs_remote_input();
- repo = xmalloc(MAXPATHLEN);
cvs_get_repository_path(".", repo, MAXPATHLEN);
STRIP_SLASH(repo);
@@ -640,7 +633,6 @@ cvs_client_updated(char *data)
fpath = rpath + strlen(repo) + 1;
if ((wdir = dirname(fpath)) == NULL)
fatal("cvs_client_updated: dirname: %s", strerror(errno));
- xfree(repo);
flen = strtonum(len, 0, INT_MAX, &errstr);
if (errstr != NULL)
@@ -729,7 +721,7 @@ void
cvs_client_set_static_directory(char *data)
{
FILE *fp;
- char *dir, *fpath;
+ char *dir, fpath[MAXPATHLEN];
if (cvs_cmdop == CVS_OP_EXPORT)
return;
@@ -739,24 +731,21 @@ cvs_client_set_static_directory(char *data)
dir = cvs_remote_input();
xfree(dir);
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(data, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >=
MAXPATHLEN)
fatal("cvs_client_set_static_directory: truncation");
if ((fp = fopen(fpath, "w+")) == NULL) {
cvs_log(LP_ERRNO, "%s", fpath);
- goto out;
+ return;
}
(void)fclose(fp);
-out:
- xfree(fpath);
}
void
cvs_client_clear_static_directory(char *data)
{
- char *dir, *fpath;
+ char *dir, fpath[MAXPATHLEN];
if (cvs_cmdop == CVS_OP_EXPORT)
return;
@@ -766,21 +755,18 @@ cvs_client_clear_static_directory(char *data)
dir = cvs_remote_input();
xfree(dir);
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(data, CVS_PATH_STATICENTRIES, fpath, MAXPATHLEN) >=
MAXPATHLEN)
fatal("cvs_client_clear_static_directory: truncation");
(void)cvs_unlink(fpath);
-
- xfree(fpath);
}
void
cvs_client_set_sticky(char *data)
{
FILE *fp;
- char *dir, *tag, *tagpath;
+ char *dir, *tag, tagpath[MAXPATHLEN];
if (cvs_cmdop == CVS_OP_EXPORT)
return;
@@ -791,7 +777,6 @@ cvs_client_set_sticky(char *data)
xfree(dir);
tag = cvs_remote_input();
- tagpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(data, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_client_clear_sticky: truncation");
@@ -803,14 +788,13 @@ cvs_client_set_sticky(char *data)
(void)fprintf(fp, "%s\n", tag);
(void)fclose(fp);
out:
- xfree(tagpath);
xfree(tag);
}
void
cvs_client_clear_sticky(char *data)
{
- char *dir, *tagpath;
+ char *dir, tagpath[MAXPATHLEN];
if (cvs_cmdop == CVS_OP_EXPORT)
return;
@@ -820,13 +804,10 @@ cvs_client_clear_sticky(char *data)
dir = cvs_remote_input();
xfree(dir);
- tagpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(data, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_client_clear_sticky: truncation");
(void)cvs_unlink(tagpath);
-
- xfree(tagpath);
}
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index 775f8f4244a..eb7b6e2f635 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.99 2007/01/18 15:26:52 xsa Exp $ */
+/* $OpenBSD: commit.c,v 1.100 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -212,7 +212,7 @@ cvs_commit_local(struct cvs_file *cf)
int l, openflags, rcsflags;
char rbuf[24], nbuf[24];
CVSENTRIES *entlist;
- char *attic, *repo, *rcsfile;
+ char attic[MAXPATHLEN], repo[MAXPATHLEN], rcsfile[MAXPATHLEN];
cvs_log(LP_TRACE, "cvs_commit_local(%s)", cf->file_path);
cvs_file_classify(cf, NULL, 0);
@@ -247,8 +247,6 @@ cvs_commit_local(struct cvs_file *cf)
cvs_log(LP_ERR, "warning: expected %s "
"to be dead", cf->file_path);
- rcsfile = xmalloc(MAXPATHLEN);
- repo = xmalloc(MAXPATHLEN);
cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
l = snprintf(rcsfile, MAXPATHLEN, "%s/%s%s",
repo, cf->file_name, RCS_FILE_EXT);
@@ -262,8 +260,6 @@ cvs_commit_local(struct cvs_file *cf)
xfree(cf->file_rpath);
cf->file_rpath = xstrdup(rcsfile);
- xfree(rcsfile);
- xfree(repo);
rcsflags = RCS_READ | RCS_PARSE_FULLY;
openflags = O_RDONLY;
@@ -353,8 +349,6 @@ cvs_commit_local(struct cvs_file *cf)
cvs_ent_remove(entlist, cf->file_name);
cvs_ent_close(entlist, ENT_SYNC);
- repo = xmalloc(MAXPATHLEN);
- attic = xmalloc(MAXPATHLEN);
cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
l = snprintf(attic, MAXPATHLEN, "%s/%s", repo, CVS_PATH_ATTIC);
@@ -373,9 +367,6 @@ cvs_commit_local(struct cvs_file *cf)
fatal("cvs_commit_local: failed to move %s to Attic",
cf->file_path);
- xfree(repo);
- xfree(attic);
-
if (cvs_server_active == 1)
cvs_server_update_entry("Remove-entry", cf);
}
@@ -428,18 +419,15 @@ commit_desc_set(struct cvs_file *cf)
{
BUF *bp;
int l, fd;
- char *desc_path, *desc;
+ char desc_path[MAXPATHLEN], *desc;
- desc_path = xmalloc(MAXPATHLEN);
l = snprintf(desc_path, MAXPATHLEN, "%s/%s%s",
CVS_PATH_CVSDIR, cf->file_name, CVS_DESCR_FILE_EXT);
if (l == -1 || l >= MAXPATHLEN)
fatal("commit_desc_set: overflow");
- if ((fd = open(desc_path, O_RDONLY)) == -1) {
- xfree(desc_path);
+ if ((fd = open(desc_path, O_RDONLY)) == -1)
return;
- }
bp = cvs_buf_load_fd(fd, BUF_AUTOEXT);
cvs_buf_putc(bp, '\0');
@@ -451,5 +439,4 @@ commit_desc_set(struct cvs_file *cf)
(void)cvs_unlink(desc_path);
xfree(desc);
- xfree(desc_path);
}
diff --git a/usr.bin/cvs/edit.c b/usr.bin/cvs/edit.c
index ed252c79801..79fcdb6e51b 100644
--- a/usr.bin/cvs/edit.c
+++ b/usr.bin/cvs/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.30 2007/01/25 11:09:21 xsa Exp $ */
+/* $OpenBSD: edit.c,v 1.31 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006, 2007 Xavier Santolaria <xsa@openbsd.org>
*
@@ -253,7 +253,8 @@ cvs_edit_local(struct cvs_file *cf)
FILE *fp;
struct tm *t;
time_t now;
- char *bfpath, timebuf[64], thishost[MAXHOSTNAMELEN], wdir[MAXPATHLEN];
+ char bfpath[MAXPATHLEN], timebuf[64], thishost[MAXHOSTNAMELEN];
+ char wdir[MAXPATHLEN];
if (cvs_noexec == 1)
return;
@@ -297,7 +298,6 @@ cvs_edit_local(struct cvs_file *cf)
if (fchmod(cf->fd, 0644) == -1)
fatal("cvs_edit_local: fchmod %s", strerror(errno));
- bfpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(CVS_PATH_BASEDIR, cf->file_name, bfpath,
MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_edit_local: truncation");
@@ -309,8 +309,6 @@ cvs_edit_local(struct cvs_file *cf)
if (cvs_file_copy(cf->file_path, bfpath) == -1)
fatal("cvs_edit_local: cvs_file_copy failed");
- xfree(bfpath);
-
(void)cvs_base_handle(cf, BASE_ADD);
}
@@ -326,7 +324,8 @@ cvs_unedit_local(struct cvs_file *cf)
struct stat st;
struct tm *t;
time_t now;
- char *bfpath, timebuf[64], thishost[MAXHOSTNAMELEN], wdir[MAXPATHLEN];
+ char bfpath[MAXPATHLEN], timebuf[64], thishost[MAXHOSTNAMELEN];
+ char wdir[MAXPATHLEN];
RCSNUM *ba_rev;
if (cvs_noexec == 1)
@@ -336,28 +335,22 @@ cvs_unedit_local(struct cvs_file *cf)
cvs_file_classify(cf, NULL, 0);
- bfpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(CVS_PATH_BASEDIR, cf->file_name, bfpath,
MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_unedit_local: truncation");
- if (stat(bfpath, &st) == -1) {
- xfree(bfpath);
+ if (stat(bfpath, &st) == -1)
return;
- }
if (cvs_file_cmp(cf->file_path, bfpath) != 0) {
cvs_printf("%s has been modified; revert changes? ",
cf->file_name);
- if (cvs_yesno() == -1) {
- xfree(bfpath);
+ if (cvs_yesno() == -1)
return;
- }
}
cvs_rename(bfpath, cf->file_path);
- xfree(bfpath);
if ((fp = fopen(CVS_PATH_NOTIFY, "a")) == NULL)
fatal("cvs_unedit_local: fopen: `%s': %s",
diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c
index c1275d4ae27..b0a2f557045 100644
--- a/usr.bin/cvs/entries.c
+++ b/usr.bin/cvs/entries.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entries.c,v 1.68 2007/01/24 13:55:11 pyr Exp $ */
+/* $OpenBSD: entries.c,v 1.69 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -354,7 +354,7 @@ cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp)
FILE *fp;
int linenum;
size_t len;
- char linebuf[128], *tagpath;
+ char linebuf[128], tagpath[MAXPATHLEN];
if (tagp != NULL)
*tagp = NULL;
@@ -365,16 +365,14 @@ cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp)
if (nbp != NULL)
*nbp = 0;
- tagpath = xmalloc(MAXPATHLEN);
-
if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN)
- goto out;
+ return;
if ((fp = fopen(tagpath, "r")) == NULL) {
if (errno != ENOENT)
cvs_log(LP_NOTICE, "failed to open `%s' : %s", tagpath,
strerror(errno));
- goto out;
+ return;
}
linenum = 0;
@@ -413,23 +411,19 @@ cvs_parse_tagfile(char *dir, char **tagp, char **datep, int *nbp)
cvs_log(LP_NOTICE, "failed to read line from `%s'", tagpath);
(void)fclose(fp);
-out:
- xfree(tagpath);
}
void
cvs_write_tagfile(char *dir, char *tag, char *date, int nb)
{
FILE *fp;
- char *tagpath;
+ char tagpath[MAXPATHLEN];
if (cvs_noexec == 1)
return;
- tagpath = xmalloc(MAXPATHLEN);
-
if (cvs_path_cat(dir, CVS_PATH_TAG, tagpath, MAXPATHLEN) >= MAXPATHLEN)
- goto out;
+ return;
if ((tag != NULL) || (date != NULL)) {
if ((fp = fopen(tagpath, "w+")) == NULL) {
@@ -437,7 +431,7 @@ cvs_write_tagfile(char *dir, char *tag, char *date, int nb)
cvs_log(LP_NOTICE, "failed to open `%s' : %s",
tagpath, strerror(errno));
}
- goto out;
+ return;
}
if (tag != NULL) {
if (nb != 0)
@@ -450,8 +444,5 @@ cvs_write_tagfile(char *dir, char *tag, char *date, int nb)
(void)fclose(fp);
} else {
(void)cvs_unlink(tagpath);
- goto out;
}
-out:
- xfree(tagpath);
}
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index 0cab5834ad5..5972af45e0a 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.175 2007/01/23 01:53:38 ray Exp $ */
+/* $OpenBSD: file.c,v 1.176 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
@@ -74,10 +74,7 @@ cvs_file_init(void)
int i, l;
FILE *ifp;
size_t len;
- char *path, *buf;
-
- path = xmalloc(MAXPATHLEN);
- buf = xmalloc(MAXNAMLEN);
+ char path[MAXPATHLEN], buf[MAXNAMLEN];
TAILQ_INIT(&cvs_ign_pats);
TAILQ_INIT(&dir_ign_pats);
@@ -109,9 +106,6 @@ cvs_file_init(void)
(void)fclose(ifp);
}
-
- xfree(path);
- xfree(buf);
}
void
@@ -207,9 +201,7 @@ cvs_file_get_cf(const char *d, const char *f, int fd, int type)
{
int l;
struct cvs_file *cf;
- char *p, *rpath;
-
- rpath = xmalloc(MAXPATHLEN);
+ char *p, rpath[MAXPATHLEN];
l = snprintf(rpath, MAXPATHLEN, "%s/%s", d, f);
if (l == -1 || l >= MAXPATHLEN)
@@ -230,7 +222,6 @@ cvs_file_get_cf(const char *d, const char *f, int fd, int type)
cf->file_status = cf->file_flags = 0;
cf->file_ent = NULL;
- xfree(rpath);
return (cf);
}
@@ -241,10 +232,7 @@ cvs_file_walklist(struct cvs_flisthead *fl, struct cvs_recursion *cr)
struct stat st;
struct cvs_file *cf;
struct cvs_filelist *l, *nxt;
- char *d, *f, *repo, *fpath;
-
- fpath = xmalloc(MAXPATHLEN);
- repo = xmalloc(MAXPATHLEN);
+ char *d, *f, repo[MAXPATHLEN], fpath[MAXPATHLEN];
for (l = TAILQ_FIRST(fl); l != NULL; l = nxt) {
if (cvs_quit)
@@ -334,9 +322,6 @@ next:
xfree(l->file_path);
xfree(l);
}
-
- xfree(fpath);
- xfree(repo);
}
void
@@ -355,7 +340,7 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr)
struct cvs_ent_line *line;
struct cvs_flisthead fl, dl;
CVSENTRIES *entlist;
- char *buf, *ebuf, *cp, *repo, *fpath;
+ char *buf, *ebuf, *cp, repo[MAXPATHLEN], fpath[MAXPATHLEN];
cvs_log(LP_TRACE, "cvs_file_walkdir(%s)", cf->file_path);
@@ -368,8 +353,6 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr)
if (cf->file_status == FILE_SKIP)
return;
- fpath = xmalloc(MAXPATHLEN);
-
/*
* If we do not have a admin directory inside here, dont bother,
* unless we are running import.
@@ -382,7 +365,6 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr)
l = stat(fpath, &st);
if (cvs_cmdop != CVS_OP_IMPORT &&
(l == -1 || (l == 0 && !S_ISDIR(st.st_mode)))) {
- xfree(fpath);
return;
}
@@ -544,7 +526,6 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr)
cvs_ent_close(entlist, ENT_NOSYNC);
if (cr->flags & CR_REPO) {
- repo = xmalloc(MAXPATHLEN);
cvs_get_repository_path(cf->file_path, repo, MAXPATHLEN);
cvs_repository_lock(repo);
@@ -555,16 +536,12 @@ cvs_file_walkdir(struct cvs_file *cf, struct cvs_recursion *cr)
cvs_file_walklist(&fl, cr);
cvs_file_freelist(&fl);
- if (cr->flags & CR_REPO) {
+ if (cr->flags & CR_REPO)
cvs_repository_unlock(repo);
- xfree(repo);
- }
cvs_file_walklist(&dl, cr);
cvs_file_freelist(&dl);
- xfree(fpath);
-
if (cr->leavedir != NULL)
cr->leavedir(cf);
}
@@ -591,7 +568,7 @@ cvs_file_classify(struct cvs_file *cf, const char *tag, int loud)
int rflags, l, ismodified, rcsdead, verbose;
CVSENTRIES *entlist = NULL;
const char *state;
- char *repo, *rcsfile, r1[16], r2[16];
+ char repo[MAXPATHLEN], rcsfile[MAXPATHLEN], r1[16], r2[16];
cvs_log(LP_TRACE, "cvs_file_classify(%s)", cf->file_path);
@@ -602,9 +579,6 @@ cvs_file_classify(struct cvs_file *cf, const char *tag, int loud)
verbose = (verbosity > 1 && loud == 1);
- repo = xmalloc(MAXPATHLEN);
- rcsfile = xmalloc(MAXPATHLEN);
-
cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
l = snprintf(rcsfile, MAXPATHLEN, "%s/%s",
repo, cf->file_name);
@@ -641,8 +615,6 @@ cvs_file_classify(struct cvs_file *cf, const char *tag, int loud)
else
cf->file_status = FILE_UNKNOWN;
- xfree(repo);
- xfree(rcsfile);
cvs_ent_close(entlist, ENT_NOSYNC);
return;
}
@@ -861,8 +833,6 @@ cvs_file_classify(struct cvs_file *cf, const char *tag, int loud)
}
}
- xfree(repo);
- xfree(rcsfile);
cvs_ent_close(entlist, ENT_NOSYNC);
}
diff --git a/usr.bin/cvs/init.c b/usr.bin/cvs/init.c
index 4cc4b20ecb8..1f319f99fe9 100644
--- a/usr.bin/cvs/init.c
+++ b/usr.bin/cvs/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.28 2007/01/13 20:29:46 joris Exp $ */
+/* $OpenBSD: init.c,v 1.29 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -95,15 +95,13 @@ void
cvs_init_local(void)
{
u_int i;
- char *path;
+ char path[MAXPATHLEN];
cvs_log(LP_TRACE, "cvs_init_local()");
/* Create repository root directory if it does not already exist */
init_mkdir(current_cvsroot->cr_dir, 0777);
- path = xmalloc(MAXPATHLEN);
-
for (i = 0; i < INIT_NDIRS; i++) {
if (cvs_path_cat(current_cvsroot->cr_dir,
cvsroot_dirs[i], path, MAXPATHLEN) >= MAXPATHLEN)
@@ -119,8 +117,6 @@ cvs_init_local(void)
init_mkfile(path, cvsroot_files[i].cf_content);
}
-
- xfree(path);
}
static void
diff --git a/usr.bin/cvs/remote.c b/usr.bin/cvs/remote.c
index a60d3e9b4f5..ed338820c18 100644
--- a/usr.bin/cvs/remote.c
+++ b/usr.bin/cvs/remote.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: remote.c,v 1.9 2007/01/25 06:44:11 otto Exp $ */
+/* $OpenBSD: remote.c,v 1.10 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -119,7 +119,7 @@ void
cvs_remote_receive_file(int fd, size_t len)
{
FILE *in;
- char *data;
+ char data[MAXBSIZE];
size_t nread, nwrite, nleft, toread;
if (cvs_server_active)
@@ -127,7 +127,6 @@ cvs_remote_receive_file(int fd, size_t len)
else
in = current_cvsroot->cr_srvout;
- data = xmalloc(MAXBSIZE);
nleft = len;
while (nleft > 0) {
@@ -147,8 +146,6 @@ cvs_remote_receive_file(int fd, size_t len)
nleft -= nread;
}
-
- xfree(data);
}
void
@@ -159,7 +156,7 @@ cvs_remote_send_file(const char *path)
size_t ret, rw;
off_t total;
struct stat st;
- char buf[16], *data;
+ char buf[16], data[MAXBSIZE];
if (cvs_server_active)
out = stdout;
@@ -184,7 +181,6 @@ cvs_remote_send_file(const char *path)
fatal("cvs_remote_send_file: fdopen %s", strerror(errno));
total = 0;
- data = xmalloc(MAXBSIZE);
while ((ret = fread(data, sizeof(char), MAXBSIZE, in)) != 0) {
rw = fwrite(data, sizeof(char), ret, out);
if (rw != ret)
@@ -197,8 +193,6 @@ cvs_remote_send_file(const char *path)
total += ret;
}
- xfree(data);
-
if (total != st.st_size)
fatal("length mismatch, %lld vs %lld", total, st.st_size);
diff --git a/usr.bin/cvs/repository.c b/usr.bin/cvs/repository.c
index 2ff62dc3434..5f92673c806 100644
--- a/usr.bin/cvs/repository.c
+++ b/usr.bin/cvs/repository.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: repository.c,v 1.8 2007/01/19 23:23:21 joris Exp $ */
+/* $OpenBSD: repository.c,v 1.9 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -93,10 +93,7 @@ cvs_repository_getdir(const char *dir, const char *wdir,
DIR *dirp;
struct stat st;
struct dirent *dp;
- char *s, *fpath, *rpath;
-
- rpath = xmalloc(MAXPATHLEN);
- fpath = xmalloc(MAXPATHLEN);
+ char *s, fpath[MAXPATHLEN], rpath[MAXPATHLEN];
if ((dirp = opendir(dir)) == NULL)
fatal("cvs_repository_getdir: failed to open '%s'", dir);
@@ -168,8 +165,5 @@ cvs_repository_getdir(const char *dir, const char *wdir,
}
}
- xfree(rpath);
- xfree(fpath);
-
(void)closedir(dirp);
}
diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c
index 70ef3f0a398..42a3cfdf51a 100644
--- a/usr.bin/cvs/server.c
+++ b/usr.bin/cvs/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.50 2007/01/18 16:45:52 joris Exp $ */
+/* $OpenBSD: server.c,v 1.51 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -220,42 +220,36 @@ void
cvs_server_static_directory(char *data)
{
FILE *fp;
- char *fpath;
+ char fpath[MAXPATHLEN];
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(server_currentdir, CVS_PATH_STATICENTRIES, fpath,
MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_server_static_directory: truncation");
if ((fp = fopen(fpath, "w+")) == NULL) {
cvs_log(LP_ERRNO, "%s", fpath);
- goto out;
+ return;
}
(void)fclose(fp);
-out:
- xfree(fpath);
}
void
cvs_server_sticky(char *data)
{
FILE *fp;
- char *tagpath;
+ char tagpath[MAXPATHLEN];
- tagpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(server_currentdir, CVS_PATH_TAG, tagpath,
MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_server_sticky: truncation");
if ((fp = fopen(tagpath, "w+")) == NULL) {
cvs_log(LP_ERRNO, "%s", tagpath);
- goto out;
+ return;
}
(void)fprintf(fp, "%s\n", data);
(void)fclose(fp);
-out:
- xfree(tagpath);
}
void
@@ -299,7 +293,7 @@ cvs_server_directory(char *data)
{
int l;
CVSENTRIES *entlist;
- char *dir, *repo, *parent, *entry, *dirn, *p;
+ char *dir, *repo, *parent, entry[CVS_ENT_MAXLINELEN], *dirn, *p;
dir = cvs_remote_input();
STRIP_SLASH(dir);
@@ -331,14 +325,12 @@ cvs_server_directory(char *data)
if (strcmp(parent, ".")) {
entlist = cvs_ent_open(parent);
- entry = xmalloc(CVS_ENT_MAXLINELEN);
l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", dirn);
if (l == -1 || l >= CVS_ENT_MAXLINELEN)
fatal("cvs_server_directory: overflow");
cvs_ent_add(entlist, entry);
cvs_ent_close(entlist, ENT_SYNC);
- xfree(entry);
}
if (server_currentdir != NULL)
@@ -366,7 +358,7 @@ cvs_server_modified(char *data)
size_t flen;
mode_t fmode;
const char *errstr;
- char *mode, *len, *fpath;
+ char *mode, *len, fpath[MAXPATHLEN];
mode = cvs_remote_input();
len = cvs_remote_input();
@@ -379,7 +371,6 @@ cvs_server_modified(char *data)
fatal("cvs_server_modified: %s", errstr);
xfree(len);
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(server_currentdir, data, fpath, MAXPATHLEN) >=
MAXPATHLEN)
fatal("cvs_server_modified: truncation");
@@ -392,7 +383,6 @@ cvs_server_modified(char *data)
if (fchmod(fd, 0600) == -1)
fatal("cvs_server_modified: failed to set file mode");
- xfree(fpath);
(void)close(fd);
}
@@ -405,12 +395,11 @@ void
cvs_server_unchanged(char *data)
{
int fd;
- char *fpath;
+ char fpath[MAXPATHLEN];
CVSENTRIES *entlist;
struct cvs_ent *ent;
struct timeval tv[2];
- fpath = xmalloc(MAXPATHLEN);
if (cvs_path_cat(server_currentdir, data, fpath, MAXPATHLEN) >=
MAXPATHLEN)
fatal("cvs_server_unchanged: truncation");
@@ -434,7 +423,6 @@ cvs_server_unchanged(char *data)
fatal("cvs_server_unchanged: failed to set mode");
cvs_ent_free(ent);
- xfree(fpath);
(void)close(fd);
}
@@ -624,12 +612,11 @@ void
cvs_server_update_entry(const char *resp, struct cvs_file *cf)
{
int l;
- char *p, *response;
+ char *p, response[MAXPATHLEN];
if ((p = strrchr(cf->file_rpath, ',')) != NULL)
*p = '\0';
- response = xmalloc(MAXPATHLEN);
l = snprintf(response, MAXPATHLEN, "%s %s/", resp, cf->file_wd);
if (l == -1 || l >= MAXPATHLEN)
fatal("cvs_server_update_entry: overflow");
@@ -639,6 +626,4 @@ cvs_server_update_entry(const char *resp, struct cvs_file *cf)
if (p != NULL)
*p = ',';
-
- xfree(response);
}
diff --git a/usr.bin/cvs/update.c b/usr.bin/cvs/update.c
index 381af43a804..c94d294d965 100644
--- a/usr.bin/cvs/update.c
+++ b/usr.bin/cvs/update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: update.c,v 1.88 2007/01/23 16:42:19 joris Exp $ */
+/* $OpenBSD: update.c,v 1.89 2007/01/25 18:56:33 otto Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
*
@@ -182,12 +182,11 @@ cvs_update_leavedir(struct cvs_file *cf)
struct cvs_ent *ent;
struct cvs_ent_line *line;
CVSENTRIES *entlist;
- char *export;
+ char export[MAXPATHLEN];
cvs_log(LP_TRACE, "cvs_update_leavedir(%s)", cf->file_path);
if (cvs_cmdop == CVS_OP_EXPORT) {
- export = xmalloc(MAXPATHLEN);
if (cvs_path_cat(cf->file_path, CVS_PATH_CVSDIR, export,
MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_update_leavedir: truncation");
@@ -197,7 +196,6 @@ cvs_update_leavedir(struct cvs_file *cf)
fatal("cvs_update_leavedir: %s: %s:", export,
strerror(errno));
- xfree(export);
return;
}