From bb6dbcf3b2a0d48c5fc4d87972a640bdeccff1ea Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 10 Jan 2001 07:13:58 +0000 Subject: Fix some memory leaks Add memory leak detection assitance. --- sys/netgraph/ng_parse.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'sys/netgraph/ng_parse.c') diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c index 15d122e..cd545c3 100644 --- a/sys/netgraph/ng_parse.c +++ b/sys/netgraph/ng_parse.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,12 @@ #include #include +#ifdef NG_SEPARATE_MALLOC +MALLOC_DEFINE(M_NETGRAPH_PARSE, "netgraph_parse", "netgraph parse info"); +#else +#define M_NETGRAPH_PARSE M_NETGRAPH +#endif + /* Compute alignment for primitive integral types */ struct int16_temp { char x; @@ -714,7 +721,7 @@ ng_string_parse(const struct ng_parse_type *type, return (EINVAL); *off += len; bcopy(sval, buf, slen + 1); - FREE(sval, M_NETGRAPH); + FREE(sval, M_NETGRAPH_PARSE); *buflen = slen + 1; return (0); } @@ -730,7 +737,7 @@ ng_string_unparse(const struct ng_parse_type *type, return (ENOMEM); NG_PARSE_APPEND("%s", s); *off += strlen(raw) + 1; - FREE(s, M_NETGRAPH); + FREE(s, M_NETGRAPH_PARSE); return (0); } @@ -776,7 +783,7 @@ ng_fixedstring_parse(const struct ng_parse_type *type, return (E2BIG); *off += len; bcopy(sval, buf, slen); - FREE(sval, M_NETGRAPH); + FREE(sval, M_NETGRAPH_PARSE); bzero(buf + slen, fi->bufSize - slen); *buflen = fi->bufSize; return (0); @@ -878,7 +885,7 @@ ng_sizedstring_parse(const struct ng_parse_type *type, *off += len; *((u_int16_t *)buf) = (u_int16_t)slen; bcopy(sval, buf + 2, slen); - FREE(sval, M_NETGRAPH); + FREE(sval, M_NETGRAPH_PARSE); *buflen = 2 + slen; return (0); } @@ -894,7 +901,7 @@ ng_sizedstring_unparse(const struct ng_parse_type *type, if (s == NULL) return (ENOMEM); NG_PARSE_APPEND("%s", s); - FREE(s, M_NETGRAPH); + FREE(s, M_NETGRAPH_PARSE); *off += slen + 2; return (0); } @@ -1020,16 +1027,16 @@ ng_bytearray_parse(const struct ng_parse_type *type, arraylen = (*getLength)(type, start, buf); if (arraylen > *buflen) { - FREE(str, M_NETGRAPH); + FREE(str, M_NETGRAPH_PARSE); return (ERANGE); } if (slen > arraylen) { - FREE(str, M_NETGRAPH); + FREE(str, M_NETGRAPH_PARSE); return (E2BIG); } bcopy(str, buf, slen); bzero(buf + slen, arraylen - slen); - FREE(str, M_NETGRAPH); + FREE(str, M_NETGRAPH_PARSE); *off += toklen; *buflen = arraylen; return (0); @@ -1122,7 +1129,7 @@ ng_parse_composite(const struct ng_parse_type *type, const char *s, int align, len, blen, error = 0; /* Initialize */ - MALLOC(foff, int *, num * sizeof(*foff), M_NETGRAPH, M_NOWAIT | M_ZERO); + MALLOC(foff, int *, num * sizeof(*foff), M_NETGRAPH_PARSE, M_NOWAIT | M_ZERO); if (foff == NULL) { error = ENOMEM; goto done; @@ -1276,7 +1283,7 @@ gotIndex: *buflen = blen; done: if (foff != NULL) - FREE(foff, M_NETGRAPH); + FREE(foff, M_NETGRAPH_PARSE); return (error); } @@ -1294,7 +1301,7 @@ ng_unparse_composite(const struct ng_parse_type *type, const u_char *data, u_char *workBuf; /* Get workspace for checking default values */ - MALLOC(workBuf, u_char *, workSize, M_NETGRAPH, M_NOWAIT); + MALLOC(workBuf, u_char *, workSize, M_NETGRAPH_PARSE, M_NOWAIT); if (workBuf == NULL) return (ENOMEM); @@ -1340,14 +1347,14 @@ ng_unparse_composite(const struct ng_parse_type *type, const u_char *data, /* Print value */ if ((error = INVOKE(etype, unparse) (etype, data, off, cbuf, cbuflen)) != 0) { - FREE(workBuf, M_NETGRAPH); + FREE(workBuf, M_NETGRAPH_PARSE); return (error); } cbuflen -= strlen(cbuf); cbuf += strlen(cbuf); didOne = 1; } - FREE(workBuf, M_NETGRAPH); + FREE(workBuf, M_NETGRAPH_PARSE); /* Closing brace/bracket */ NG_PARSE_APPEND("%s%c", @@ -1581,7 +1588,7 @@ ng_parse_get_token(const char *s, int *startp, int *lenp) case '"': if ((t = ng_get_string_token(s, startp, lenp, NULL)) == NULL) return T_ERROR; - FREE(t, M_NETGRAPH); + FREE(t, M_NETGRAPH_PARSE); return T_STRING; default: for (i = *startp + 1; s[i] != '\0' && !isspace(s[i]) @@ -1609,7 +1616,7 @@ ng_get_string_token(const char *s, int *startp, int *lenp, int *slenp) start = *startp; if (s[*startp] != '"') return (NULL); - MALLOC(cbuf, char *, strlen(s + start), M_NETGRAPH, M_NOWAIT); + MALLOC(cbuf, char *, strlen(s + start), M_NETGRAPH_PARSE, M_NOWAIT); if (cbuf == NULL) return (NULL); strcpy(cbuf, s + start + 1); @@ -1691,7 +1698,7 @@ ng_encode_string(const char *raw, int slen) int off = 0; int i; - MALLOC(cbuf, char *, strlen(raw) * 4 + 3, M_NETGRAPH, M_NOWAIT); + MALLOC(cbuf, char *, strlen(raw) * 4 + 3, M_NETGRAPH_PARSE, M_NOWAIT); if (cbuf == NULL) return (NULL); cbuf[off++] = '"'; -- cgit v1.1