Skip to content

Commit c8843c9

Browse files
committed
snmp: initialize session variables to NULL and free peername in exit function
Signed-off-by: k402xxxcenxxx <[email protected]>
1 parent f7e4f0b commit c8843c9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

plugins/in_snmp/in_snmp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include <net-snmp/net-snmp-config.h>
5-
#include <net-snmp/net-snmp-includes.h>
6-
#include <openssl/crypto.h>
5+
#include <net-snmp/net-snmp-includes.h>\
76
#include <msgpack.h>
87
#include <fluent-bit/flb_input.h>
98
#include <fluent-bit/flb_time.h>
@@ -121,9 +120,9 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
121120
int ret = 0;
122121
struct flb_snmp *ctx = in_context;
123122

124-
netsnmp_session *ss;
123+
netsnmp_session *ss = NULL;
125124
netsnmp_pdu *pdu;
126-
netsnmp_pdu *response;
125+
netsnmp_pdu *response = NULL;
127126

128127
oid anOID[MAX_OID_LEN], name[MAX_OID_LEN], end_oid[MAX_OID_LEN];
129128
size_t anOID_len, name_len, end_len;
@@ -137,7 +136,7 @@ static int in_snmp_collect(struct flb_input_instance *ins, struct flb_config *co
137136
int buf_overflow = 0;
138137
bool is_walk = false;
139138

140-
char *err;
139+
char *err = NULL;
141140

142141
if (strcmp(ctx->oid_type, "get") == 0) {
143142
is_walk = false;
@@ -438,6 +437,9 @@ static int in_snmp_exit(void *data, struct flb_config *config)
438437

439438
flb_log_event_encoder_destroy(&ctx->log_encoder);
440439

440+
if (ctx->session.peername) {
441+
flb_free((void *)ctx->session.peername);
442+
}
441443
flb_free(ctx);
442444
snmp_shutdown(PLUGIN_NAME);
443445

0 commit comments

Comments
 (0)