summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorBret Lambert <blambert@cvs.openbsd.org>2014-04-16 08:52:29 +0000
committerBret Lambert <blambert@cvs.openbsd.org>2014-04-16 08:52:29 +0000
commitd1397d0668be020d0d2e4c7688a15f2b8cc843f5 (patch)
tree3e39a0c178f980ef1c337e73b3c151b5373386ba /usr.sbin
parent107a65fd3555f0dbcdd93b99670910f0091ce826 (diff)
close memory leaks in snmp client code
ok reyk@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/snmpctl/snmpclient.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/usr.sbin/snmpctl/snmpclient.c b/usr.sbin/snmpctl/snmpclient.c
index 146d04d3b7e..348ada264ba 100644
--- a/usr.sbin/snmpctl/snmpclient.c
+++ b/usr.sbin/snmpctl/snmpclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpclient.c,v 1.8 2013/10/07 11:40:09 reyk Exp $ */
+/* $OpenBSD: snmpclient.c,v 1.9 2014/04/16 08:52:28 blambert Exp $ */
/*
* Copyright (c) 2013 Reyk Floeter <reyk@openbsd.org>
@@ -290,12 +290,13 @@ snmpc_sendreq(struct snmpc *sc, u_long type)
/* SNMP header */
sc->sc_msgid = arc4random();
- if ((root = ber_add_sequence(NULL)) == NULL ||
- (b = ber_printf_elements(root, "ds{tddd{{O0}}",
+ if ((root = ber_add_sequence(NULL)) == NULL)
+ return (-1);
+ if ((b = ber_printf_elements(root, "ds{tddd{{O0}}",
sc->sc_version, sc->sc_community, BER_CLASS_CONTEXT, type,
sc->sc_msgid, 0, erroridx, &sc->sc_oid)) == NULL) {
errno = EINVAL;
- return (-1);
+ goto fail;
}
#ifdef DEBUG
@@ -308,13 +309,21 @@ snmpc_sendreq(struct snmpc *sc, u_long type)
len = ber_write_elements(&ber, root);
if (ber_get_writebuf(&ber, (void *)&ptr) < 1)
- return (-1);
+ goto berfail;
if (sendto(sc->sc_fd, ptr, len, 0,
(struct sockaddr *)&sc->sc_addr, sc->sc_addr_len) == -1)
- return (-1);
+ goto berfail;
+ ber_free_elements(root);
+ ber_free(&ber);
return (0);
+
+berfail:
+ ber_free(&ber);
+fail:
+ ber_free_elements(root);
+ return (-1);
}
int