diff options
author | Vincent Labrecque <vincent@cvs.openbsd.org> | 2004-07-14 05:08:21 +0000 |
---|---|---|
committer | Vincent Labrecque <vincent@cvs.openbsd.org> | 2004-07-14 05:08:21 +0000 |
commit | 1a98f94ba8dfd6e7e3dc11fb2e954b2c9df00107 (patch) | |
tree | 12d67953cd6fa98c0a7fd6c910d4cab1812ce560 | |
parent | 37ac26a90c8eade30d66db166a50c2ec5b67b719 (diff) |
fix memleak on rcsnum reuse
initialize new members to 0
-rw-r--r-- | usr.bin/cvs/rcsnum.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c index b2694c62da7..0571e1a2907 100644 --- a/usr.bin/cvs/rcsnum.c +++ b/usr.bin/cvs/rcsnum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsnum.c,v 1.1 2004/07/13 22:02:40 jfb Exp $ */ +/* $OpenBSD: rcsnum.c,v 1.2 2004/07/14 05:08:20 vincent Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -191,11 +191,14 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) if (!isdigit(*str)) return (-1); - nump->rn_id = (u_int16_t *)malloc(sizeof(u_int16_t)); - if (nump->rn_id == NULL) - return (-1); + if (nump->rn_id == NULL) { + nump->rn_id = (u_int16_t *)malloc(sizeof(u_int16_t)); + if (nump->rn_id == NULL) + return (-1); + } nump->rn_len = 0; + nump->rn_id[nump->rn_len] = 0; for (sp = str; ; sp++) { if (!isdigit(*sp) && (*sp != '.')) { @@ -216,6 +219,7 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) return (-1); } nump->rn_id = (u_int16_t *)tmp; + nump->rn_id[nump->rn_len] = 0; continue; } |