summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoris Vink <joris@cvs.openbsd.org>2007-01-12 19:28:13 +0000
committerJoris Vink <joris@cvs.openbsd.org>2007-01-12 19:28:13 +0000
commit2a0a7d337321a12b7989aaf375e262b416ac99dc (patch)
treed7d862bc2672f2e46c71f0ea9822790ea5a73cd7 /usr.bin
parent0d4487fe419f565308ab5595eebcf02edc704636 (diff)
do not leak memory from rcs_head_get()
ok niallo@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/add.c12
-rw-r--r--usr.bin/cvs/commit.c12
-rw-r--r--usr.bin/cvs/file.c4
-rw-r--r--usr.bin/cvs/rcs.c10
-rw-r--r--usr.bin/cvs/status.c8
5 files changed, 31 insertions, 15 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c
index e4e8134dbb4..cb9abda8a39 100644
--- a/usr.bin/cvs/add.c
+++ b/usr.bin/cvs/add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: add.c,v 1.67 2007/01/12 03:34:50 joris Exp $ */
+/* $OpenBSD: add.c,v 1.68 2007/01/12 19:28:12 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -251,9 +251,11 @@ add_file(struct cvs_file *cf)
char revbuf[16];
RCSNUM *head;
- if (cf->file_rcs != NULL)
- rcsnum_tostr(rcs_head_get(cf->file_rcs),
- revbuf, sizeof(revbuf));
+ if (cf->file_rcs != NULL) {
+ head = rcs_head_get(cf->file_rcs);
+ rcsnum_tostr(head, revbuf, sizeof(revbuf));
+ rcsnum_free(head);
+ }
added = stop = 0;
switch (cf->file_status) {
@@ -273,6 +275,8 @@ add_file(struct cvs_file *cf)
/* Restore the file. */
head = rcs_head_get(cf->file_rcs);
b = rcs_getrev(cf->file_rcs, head);
+ rcsnum_free(head);
+
if (b == NULL)
fatal("cvs_add_local: failed to get HEAD");
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c
index afd19bb8b66..28cec83e6b3 100644
--- a/usr.bin/cvs/commit.c
+++ b/usr.bin/cvs/commit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: commit.c,v 1.92 2007/01/12 18:27:18 joris Exp $ */
+/* $OpenBSD: commit.c,v 1.93 2007/01/12 19:28:12 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -205,6 +205,7 @@ cvs_commit_local(struct cvs_file *cf)
{
BUF *b, *d;
int isnew;
+ RCSNUM *head;
int l, openflags, rcsflags;
char rbuf[24], nbuf[24];
CVSENTRIES *entlist;
@@ -221,10 +222,13 @@ cvs_commit_local(struct cvs_file *cf)
if (cf->file_status == FILE_MODIFIED ||
cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED
- && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1))
- rcsnum_tostr(rcs_head_get(cf->file_rcs), rbuf, sizeof(rbuf));
- else
+ && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1)) {
+ head = rcs_head_get(cf->file_rcs);
+ rcsnum_tostr(head, rbuf, sizeof(rbuf));
+ rcsnum_free(head);
+ } else {
strlcpy(rbuf, "Non-existent", sizeof(rbuf));
+ }
isnew = 0;
if (cf->file_status == FILE_ADDED) {
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index a370cf90362..3e6973cca5f 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.166 2007/01/10 21:32:19 xsa Exp $ */
+/* $OpenBSD: file.c,v 1.167 2007/01/12 19:28:12 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
@@ -828,6 +828,8 @@ cvs_file_free(struct cvs_file *cf)
xfree(cf->file_wd);
xfree(cf->file_path);
+ if (cf->file_rcsrev != NULL)
+ rcsnum_free(cf->file_rcsrev);
if (cf->file_rpath != NULL)
xfree(cf->file_rpath);
if (cf->file_ent != NULL)
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c
index a096e829978..14d5dd7f729 100644
--- a/usr.bin/cvs/rcs.c
+++ b/usr.bin/cvs/rcs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcs.c,v 1.194 2007/01/12 17:25:33 joris Exp $ */
+/* $OpenBSD: rcs.c,v 1.195 2007/01/12 19:28:12 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -592,13 +592,17 @@ RCSNUM *
rcs_head_get(RCSFILE *file)
{
char br[16];
+ RCSNUM *rev;
if (file->rf_branch != NULL) {
rcsnum_tostr(file->rf_branch, br, sizeof(br));
- return (rcs_translate_tag(br, file));
+ rev = rcs_translate_tag(br, file);
+ } else {
+ rev = rcsnum_alloc();
+ rcsnum_cpy(file->rf_head, rev, 0);
}
- return (file->rf_head);
+ return (rev);
}
/*
diff --git a/usr.bin/cvs/status.c b/usr.bin/cvs/status.c
index 6bf97e2534c..5222f2bbc10 100644
--- a/usr.bin/cvs/status.c
+++ b/usr.bin/cvs/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.69 2007/01/11 02:35:55 joris Exp $ */
+/* $OpenBSD: status.c,v 1.70 2007/01/12 19:28:12 joris Exp $ */
/*
* Copyright (c) 2006 Joris Vink <joris@openbsd.org>
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
@@ -118,6 +118,7 @@ cvs_status_local(struct cvs_file *cf)
{
int l;
size_t len;
+ RCSNUM *head;
const char *status;
char buf[128], timebuf[32], revbuf[32];
struct rcs_sym *sym;
@@ -187,8 +188,9 @@ cvs_status_local(struct cvs_file *cf)
if (len >= sizeof(buf))
fatal("cvs_status_local: truncation");
} else {
- rcsnum_tostr(rcs_head_get(cf->file_rcs),
- revbuf, sizeof(revbuf));
+ head = rcs_head_get(cf->file_rcs);
+ rcsnum_tostr(head, revbuf, sizeof(revbuf));
+ rcsnum_free(head);
l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf,
cf->file_rpath);
if (l == -1 || l >= (int)sizeof(buf))