summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoris <joris@openbsd.org>2005-09-11 14:16:48 +0000
committerjoris <joris@openbsd.org>2005-09-11 14:16:48 +0000
commitf367048c77a89c0fc47e5c084067a0f47ff98ae3 (patch)
tree201dfc2c852c305e7327a880cc80599ca827ca95
parentcope with the ___moddi3 issue, same as mvme68k (diff)
downloadwireguard-openbsd-f367048c77a89c0fc47e5c084067a0f47ff98ae3.tar.xz
wireguard-openbsd-f367048c77a89c0fc47e5c084067a0f47ff98ae3.zip
only remove and free a cvsroot struct if it has been added in
cvsroot_parse(). fixes segfaults opencvs has been receiving when cvsroot_parse() fails. "go ahead" xsa@
-rw-r--r--usr.bin/cvs/cvs.h4
-rw-r--r--usr.bin/cvs/file.c4
-rw-r--r--usr.bin/cvs/root.c36
3 files changed, 27 insertions, 17 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h
index 9498cfb1503..99b9120884c 100644
--- a/usr.bin/cvs/cvs.h
+++ b/usr.bin/cvs/cvs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cvs.h,v 1.82 2005/09/06 15:29:33 joris Exp $ */
+/* $OpenBSD: cvs.h,v 1.83 2005/09/11 14:16:48 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -371,7 +371,7 @@ const char *cvs_var_get(const char *);
/* root.c */
struct cvsroot *cvsroot_parse(const char *);
-void cvsroot_free(struct cvsroot *);
+void cvsroot_remove(struct cvsroot *);
struct cvsroot *cvsroot_get(const char *);
diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c
index 24a05c41213..a0e8e62bb65 100644
--- a/usr.bin/cvs/file.c
+++ b/usr.bin/cvs/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.118 2005/09/06 17:08:05 xsa Exp $ */
+/* $OpenBSD: file.c,v 1.119 2005/09/11 14:16:48 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -1020,7 +1020,7 @@ cvs_file_free(CVSFILE *cf)
if (cf->cf_type == DT_DIR) {
if (cf->cf_root != NULL)
- cvsroot_free(cf->cf_root);
+ cvsroot_remove(cf->cf_root);
if (cf->cf_repo != NULL)
free(cf->cf_repo);
while (!SIMPLEQ_EMPTY(&(cf->cf_files))) {
diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c
index 7ca1b460f05..0b3505cf0cd 100644
--- a/usr.bin/cvs/root.c
+++ b/usr.bin/cvs/root.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: root.c,v 1.24 2005/08/10 16:01:27 joris Exp $ */
+/* $OpenBSD: root.c,v 1.25 2005/09/11 14:16:48 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -66,6 +66,7 @@ const char *cvs_methods[] = {
* the result to the cache for future hits.
*/
static TAILQ_HEAD(, cvsroot) cvs_rcache = TAILQ_HEAD_INITIALIZER(cvs_rcache);
+static void cvsroot_free(struct cvsroot *);
/*
* cvsroot_parse()
@@ -220,29 +221,38 @@ cvsroot_parse(const char *str)
return (root);
}
-
/*
- * cvsroot_free()
+ * cvsroot_remove()
*
- * Free a CVSROOT structure previously allocated and returned by
- * cvsroot_parse().
+ * Remove a CVSROOT structure from the cache, and free it.
*/
void
-cvsroot_free(struct cvsroot *root)
+cvsroot_remove(struct cvsroot *root)
{
root->cr_ref--;
if (root->cr_ref == 0) {
TAILQ_REMOVE(&cvs_rcache, root, root_cache);
- if (root->cr_str != NULL)
- free(root->cr_str);
- if (root->cr_buf != NULL)
- free(root->cr_buf);
- if (root->cr_version != NULL)
- free(root->cr_version);
- free(root);
+ cvsroot_free(root);
}
}
+/*
+ * cvsroot_free()
+ *
+ * Free a CVSROOT structure previously allocated and returned by
+ * cvsroot_parse().
+ */
+static void
+cvsroot_free(struct cvsroot *root)
+{
+ if (root->cr_str != NULL)
+ free(root->cr_str);
+ if (root->cr_buf != NULL)
+ free(root->cr_buf);
+ if (root->cr_version != NULL)
+ free(root->cr_version);
+ free(root);
+}
/*
* cvsroot_get()