Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src avoid memory leak. hint from Andrew Lunn



details:   https://anonhg.NetBSD.org/src/rev/748f8ef89639
branches:  trunk
changeset: 555606:748f8ef89639
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Nov 23 08:33:13 2003 +0000

description:
avoid memory leak.  hint from Andrew Lunn

diffstat:

 crypto/dist/kame/libipsec/policy_parse.y |  6 +++++-
 lib/libipsec/policy_parse.y              |  8 ++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diffs (52 lines):

diff -r 5a424b5d8b77 -r 748f8ef89639 crypto/dist/kame/libipsec/policy_parse.y
--- a/crypto/dist/kame/libipsec/policy_parse.y  Sun Nov 23 08:23:02 2003 +0000
+++ b/crypto/dist/kame/libipsec/policy_parse.y  Sun Nov 23 08:33:13 2003 +0000
@@ -66,7 +66,7 @@
 #define ATOX(c) \
   (isdigit(c) ? (c - '0') : (isupper(c) ? (c - 'A' + 10) : (c - 'a' + 10) ))
 
-static caddr_t pbuf = NULL;            /* sadb_x_policy buffer */
+static u_int8_t *pbuf = NULL;          /* sadb_x_policy buffer */
 static int tlen = 0;                   /* total length of pbuf */
 static int offset = 0;                 /* offset of pbuf */
 static int p_dir, p_type, p_protocol, p_mode, p_level, p_reqid;
@@ -293,6 +293,10 @@
 {
        struct sadb_x_policy *p;
 
+       if (pbuf) {
+               free(pbuf);
+               tlen = 0;
+       }
        pbuf = malloc(sizeof(struct sadb_x_policy));
        if (pbuf == NULL) {
                __ipsec_errcode = EIPSEC_NO_BUFS;
diff -r 5a424b5d8b77 -r 748f8ef89639 lib/libipsec/policy_parse.y
--- a/lib/libipsec/policy_parse.y       Sun Nov 23 08:23:02 2003 +0000
+++ b/lib/libipsec/policy_parse.y       Sun Nov 23 08:33:13 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: policy_parse.y,v 1.13 2003/11/23 08:23:02 itojun Exp $ */
+/*     $NetBSD: policy_parse.y,v 1.14 2003/11/23 08:33:13 itojun Exp $ */
 /*     $KAME: policy_parse.y,v 1.15 2003/10/02 19:37:49 itojun Exp $   */
 
 /*
@@ -67,7 +67,7 @@
 #define ATOX(c) \
   (isdigit(c) ? (c - '0') : (isupper(c) ? (c - 'A' + 10) : (c - 'a' + 10) ))
 
-static caddr_t pbuf = NULL;            /* sadb_x_policy buffer */
+static u_int8_t *pbuf = NULL;          /* sadb_x_policy buffer */
 static int tlen = 0;                   /* total length of pbuf */
 static int offset = 0;                 /* offset of pbuf */
 static int p_dir, p_type, p_protocol, p_mode, p_level, p_reqid;
@@ -294,6 +294,10 @@
 {
        struct sadb_x_policy *p;
 
+       if (pbuf) {
+               free(pbuf);
+               tlen = 0;
+       }
        pbuf = malloc(sizeof(struct sadb_x_policy));
        if (pbuf == NULL) {
                __ipsec_errcode = EIPSEC_NO_BUFS;



Home | Main Index | Thread Index | Old Index