1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## snmp_memleak.dpatch by Florian Forster <octo@noris.net>
3 ##
4 ## DP: Fix a possible memory leak in the snmp plugin: The SNMP result object
5 ## DP: was not freed when `csnmp_instance_list_add' failed.
6 ## DP: (This is upstream Git commit 0109e3c1f3a515ed716ddbdc261e0ed2e3f8e640)
8 @DPATCH@
10 diff a/src/snmp.c b/src/snmp.c
11 --- a/src/snmp.c
12 +++ b/src/snmp.c
13 @@ -1120,10 +1120,6 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
14 vb = res->variables;
15 if (vb == NULL)
16 {
17 - if (res != NULL)
18 - snmp_free_pdu (res);
19 - res = NULL;
20 -
21 status = -1;
22 break;
23 }
24 @@ -1132,10 +1128,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
25 * subtree */
26 if (csnmp_check_res_left_subtree (host, data, res) != 0)
27 {
28 - if (res != NULL)
29 - snmp_free_pdu (res);
30 - res = NULL;
31 -
32 + status = 0;
33 break;
34 }
36 @@ -1157,11 +1150,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
37 (vb != NULL) && (vb->next_variable != NULL);
38 vb = vb->next_variable)
39 /* do nothing */;
40 - if (vb == NULL)
41 - {
42 - status = -1;
43 - break;
44 - }
45 + assert (vb != NULL);
47 /* Copy OID to oid_list[data->values_len] */
48 memcpy (oid_list[data->values_len].oid, vb->name,
49 @@ -1224,6 +1213,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
50 res = NULL;
51 } /* while (status == 0) */
53 + if (res != NULL)
54 + snmp_free_pdu (res);
55 + res = NULL;
56 +
57 if (status == 0)
58 csnmp_dispatch_table (host, data, instance_list, value_table);