From 49f8748d61e452bb0962f8dbd1955014431e975c Mon Sep 17 00:00:00 2001 From: Patrick Latifi Date: Mon, 27 Mar 2006 06:13:52 +0000 Subject: Plug a memory leak for all cvs_strsplit call sites; ok xsa@ --- usr.bin/cvs/util.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'usr.bin/cvs/util.c') 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 * Copyright (c) 2005, 2006 Joris Vink @@ -1052,22 +1052,39 @@ cvs_yesno(void) * Split a string of -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); } -- cgit v1.2.3