Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/file Do reallaction of magic entries array carefully...
details: https://anonhg.NetBSD.org/src/rev/d90031729fb6
branches: trunk
changeset: 480053:d90031729fb6
user: tron <tron%NetBSD.org@localhost>
date: Fri Dec 31 13:07:59 1999 +0000
description:
Do reallaction of magic entries array carefully to avoid possible memory
leak. Patch based on PR bin/9081 by Jun-ichiro itojun Hagino.
diffstat:
usr.bin/file/apprentice.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diffs (38 lines):
diff -r f2f2310c6394 -r d90031729fb6 usr.bin/file/apprentice.c
--- a/usr.bin/file/apprentice.c Fri Dec 31 12:58:12 1999 +0000
+++ b/usr.bin/file/apprentice.c Fri Dec 31 13:07:59 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apprentice.c,v 1.17 1999/11/01 17:39:26 christos Exp $ */
+/* $NetBSD: apprentice.c,v 1.18 1999/12/31 13:07:59 tron Exp $ */
/*
* apprentice - make one pass through /etc/magic, learning its secrets.
@@ -39,7 +39,7 @@
#if 0
FILE_RCSID("@(#)Id: apprentice.c,v 1.28 1998/09/12 13:17:52 christos Exp ")
#else
-__RCSID("$NetBSD: apprentice.c,v 1.17 1999/11/01 17:39:26 christos Exp $");
+__RCSID("$NetBSD: apprentice.c,v 1.18 1999/12/31 13:07:59 tron Exp $");
#endif
#endif /* lint */
@@ -188,9 +188,10 @@
int i = 0, nd = *ndx;
struct magic *m;
char *t, *s;
+ struct magic *newmagic;
if (nd+1 >= maxmagic){
- if ((magic = (struct magic *) realloc(magic,
+ if ((newmagic = (struct magic *) realloc(magic,
sizeof(struct magic) *
maxmagic * 2)) == NULL) {
(void) fprintf(stderr, "%s: Out of memory.\n", progname);
@@ -199,6 +200,7 @@
else
exit(1);
}
+ magic = newmagic;
memset(&magic[maxmagic], 0, sizeof(struct magic) * maxmagic);
maxmagic *= 2;
}
Home |
Main Index |
Thread Index |
Old Index