diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-04-15 16:19:35 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-04-15 16:19:35 +0000 |
commit | ddca326bed4fd9cc7cd9e6491c61ae550c89bd2e (patch) | |
tree | e59d329b044b9f9c38f2739bcbf1fd9e3a9f65e7 | |
parent | e4ab656f287227a72d1638c30fb8a76730f4548b (diff) |
Fix memory leak in case aspath_snprint() returns an error (-1).
OK henning@
-rw-r--r-- | usr.sbin/bgpd/rde_attr.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c index 9fcffd15b64..9352e748da4 100644 --- a/usr.sbin/bgpd/rde_attr.c +++ b/usr.sbin/bgpd/rde_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_attr.c,v 1.44 2004/11/10 15:18:11 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.45 2005/04/15 16:19:34 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -534,7 +534,7 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len) UPDATE(); } } - /* ensure that we have a valid C-string */ + /* ensure that we have a valid C-string especially for emtpy as path */ if (size > 0) *buf = '\0'; @@ -545,13 +545,17 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len) int aspath_asprint(char **ret, void *data, u_int16_t len) { - size_t slen, plen; + size_t slen; + int plen; slen = aspath_strlen(data, len) + 1; *ret = malloc(slen); if (*ret == NULL) return (-1); + plen = aspath_snprint(*ret, slen, data, len); + if (plen == -1) + free(*ret); return (plen); } |