diff options
author | Patrick Latifi <pat@cvs.openbsd.org> | 2006-03-27 06:13:52 +0000 |
---|---|---|
committer | Patrick Latifi <pat@cvs.openbsd.org> | 2006-03-27 06:13:52 +0000 |
commit | 49f8748d61e452bb0962f8dbd1955014431e975c (patch) | |
tree | e8a3bd9cd544e09278f2904edbaa94e1ae4fab8e /usr.bin | |
parent | f918003bd62c63f053b8fe8af733ab370a6517ca (diff) |
Plug a memory leak for all cvs_strsplit call sites; ok xsa@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/util.c | 35 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 10 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 18 | ||||
-rw-r--r-- | usr.bin/rcs/rlog.c | 24 |
4 files changed, 56 insertions, 31 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); } diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index 2260cdb8809..207fb9d05e2 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.3 2006/03/17 13:40:41 niallo Exp $ */ +/* $OpenBSD: util.h,v 1.4 2006/03/27 06:13:51 pat Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -69,12 +69,18 @@ struct cvs_lines { struct cvs_tqh l_lines; }; +struct cvs_argvector { + char *str; + char **argv; +}; BUF *cvs_patchfile(const char *, const char *, int (*p)(struct cvs_lines *, struct cvs_lines *)); struct cvs_lines *cvs_splitlines(const char *); void cvs_freelines(struct cvs_lines *); int cvs_yesno(void); -char **cvs_strsplit(char *, const char *); +struct cvs_argvector *cvs_strsplit(char *, const char *); + +void cvs_argv_destroy(struct cvs_argvector *); #endif /* UTIL_H */ diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index 3b31242b1bc..9d162fb2622 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.85 2006/03/24 05:14:48 ray Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.86 2006/03/27 06:13:51 pat Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -612,26 +612,26 @@ rcs_main(int argc, char **argv) /* entries to add to the access list */ if (alist != NULL) { - char **aargv; + struct cvs_argvector *aargv; aargv = cvs_strsplit(alist, ","); - for (j = 0; aargv[j] != NULL; j++) - rcs_access_add(file, aargv[j]); + for (j = 0; aargv->argv[j] != NULL; j++) + rcs_access_add(file, aargv->argv[j]); - xfree(aargv); + cvs_argv_destroy(aargv); } if (comment != NULL) rcs_comment_set(file, comment); if (elist != NULL) { - char **eargv; + struct cvs_argvector *eargv; eargv = cvs_strsplit(elist, ","); - for (j = 0; eargv[j] != NULL; j++) - rcs_access_remove(file, eargv[j]); + for (j = 0; eargv->argv[j] != NULL; j++) + rcs_access_remove(file, eargv->argv[j]); - xfree(eargv); + cvs_argv_destroy(eargv); } else if (rcsflags & RCS_EFLAG) { struct rcs_access *rap; diff --git a/usr.bin/rcs/rlog.c b/usr.bin/rcs/rlog.c index fcdea352b57..b01927cf8e2 100644 --- a/usr.bin/rcs/rlog.c +++ b/usr.bin/rcs/rlog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rlog.c,v 1.33 2006/03/24 05:14:48 ray Exp $ */ +/* $OpenBSD: rlog.c,v 1.34 2006/03/27 06:13:51 pat Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> @@ -217,7 +217,7 @@ rlog_rev_print(struct rcs_delta *rdp) { int i, found; char *author, numb[64]; - char **largv, **sargv, **wargv; + struct cvs_argvector *largv, *sargv, *wargv; i = found = 0; author = NULL; @@ -236,40 +236,42 @@ rlog_rev_print(struct rcs_delta *rdp) if (rdp->rd_locker == NULL) return; largv = cvs_strsplit(llist, ","); - for (i = 0; largv[i] != NULL; i++) { - if (strcmp(rdp->rd_locker, largv[i]) == 0) { + for (i = 0; largv->argv[i] != NULL; i++) { + if (strcmp(rdp->rd_locker, largv->argv[i]) + == 0) { found++; break; } found = 0; } - xfree(largv); + cvs_argv_destroy(largv); } } /* -sstates */ if (slist != NULL) { sargv = cvs_strsplit(slist, ","); - for (i = 0; sargv[i] != NULL; i++) { - if (strcmp(rdp->rd_state, sargv[i]) == 0) { + for (i = 0; sargv->argv[i] != NULL; i++) { + if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) { found++; break; } found = 0; } - xfree(sargv); + cvs_argv_destroy(sargv); } /* -w[logins] */ if (wflag == 1) { if (wlist != NULL) { wargv = cvs_strsplit(wlist, ","); - for (i = 0; wargv[i] != NULL; i++) { - if (strcmp(rdp->rd_author, wargv[i]) == 0) { + for (i = 0; wargv->argv[i] != NULL; i++) { + if (strcmp(rdp->rd_author, wargv->argv[i]) + == 0) { found++; break; } found = 0; } - xfree(wargv); + cvs_argv_destroy(wargv); } else { if ((author = getlogin()) == NULL) fatal("getlogin failed"); |