summaryrefslogtreecommitdiff
path: root/usr.bin/cvs/util.c
diff options
context:
space:
mode:
authorPatrick Latifi <pat@cvs.openbsd.org>2006-03-27 06:13:52 +0000
committerPatrick Latifi <pat@cvs.openbsd.org>2006-03-27 06:13:52 +0000
commit49f8748d61e452bb0962f8dbd1955014431e975c (patch)
treee8a3bd9cd544e09278f2904edbaa94e1ae4fab8e /usr.bin/cvs/util.c
parentf918003bd62c63f053b8fe8af733ab370a6517ca (diff)
Plug a memory leak for all cvs_strsplit call sites; ok xsa@
Diffstat (limited to 'usr.bin/cvs/util.c')
-rw-r--r--usr.bin/cvs/util.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c
index ae96c805efd..6b68bb3b7c8 100644
--- a/usr.bin/cvs/util.c
+++ b/usr.bin/cvs/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.72 2006/03/17 13:40:41 niallo Exp $ */
+/* $OpenBSD: util.c,v 1.73 2006/03/27 06:13:51 pat Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org>
@@ -1052,22 +1052,39 @@ cvs_yesno(void)
* Split a string <str> of <sep>-separated values and allocate
* an argument vector for the values found.
*/
-char **
+struct cvs_argvector *
cvs_strsplit(char *str, const char *sep)
{
- char **argv, **nargv;
+ struct cvs_argvector *av;
+ char **nargv;
char *cp, *p;
int i = 0;
cp = xstrdup(str);
- argv = (char **)xmalloc((i+1) * sizeof(char *));
+ av = xmalloc(sizeof(struct cvs_argvector));
+ av->str = cp;
+ av->argv = (char **)xmalloc((i+1) * sizeof(char *));
while ((p = strsep(&cp, sep)) != NULL) {
- argv[i++] = p;
- nargv = (char **)xrealloc((void *)argv, (i+1) * sizeof(char *));
- argv = nargv;
+ av->argv[i++] = p;
+ nargv = (char **)xrealloc((void *)av->argv,
+ (i+1) * sizeof(char *));
+ av->argv = nargv;
}
- argv[i] = NULL;
+ av->argv[i] = NULL;
+
+ return (av);
+}
- return (argv);
+/*
+ * cvs_argv_destroy()
+ *
+ * Free an argument vector previously allocated by cvs_strsplit().
+ */
+void
+cvs_argv_destroy(struct cvs_argvector *av)
+{
+ xfree(av->str);
+ xfree(av->argv);
+ xfree(av);
}