in_serial: fix leak on failure plugin initialization (CID 251471)
@@ -96,7 +96,7 @@ static inline void consume_bytes(char *buf, int bytes, int length)
}
/* Callback triggered when some serial msgs are available */
-static int in_serial_collect(struct flb_input_instance *in,
+static int cb_serial_collect(struct flb_input_instance *in,
struct flb_config *config, void *in_context)
{
int ret;
@@ -238,7 +238,7 @@ static int in_serial_collect(struct flb_input_instance *in,
}
/* Cleanup serial input */
-int in_serial_exit(void *in_context, struct flb_config *config)
+static int cb_serial_exit(void *in_context, struct flb_config *config)
{
struct flb_in_serial_config *ctx = in_context;
@@ -252,7 +252,7 @@ int in_serial_exit(void *in_context, struct flb_config *config)
}
/* Init serial input */
-int in_serial_init(struct flb_input_instance *in,
+static int cb_serial_init(struct flb_input_instance *in,
struct flb_config *config, void *data)
{
int fd;
@@ -263,12 +263,13 @@ int in_serial_init(struct flb_input_instance *in,
ctx = flb_calloc(1, sizeof(struct flb_in_serial_config));
if (!ctx) {
- perror("calloc");
+ flb_errno();
return -1;
}
ctx->format = FLB_SERIAL_FORMAT_NONE;
if (!serial_config_read(ctx, in)) {
+ flb_free(ctx);
return -1;
}
@@ -320,7 +321,7 @@ int in_serial_init(struct flb_input_instance *in,
#if __linux__
/* Set our collector based on a file descriptor event */
ret = flb_input_set_collector_event(in,
- in_serial_collect,
+ cb_serial_collect,
ctx->fd,
config);
#else
@@ -343,9 +344,9 @@ int in_serial_init(struct flb_input_instance *in,
struct flb_input_plugin in_serial_plugin = {
.name = "serial",
.description = "Serial input",
- .cb_init = in_serial_init,
+ .cb_init = cb_serial_init,
.cb_pre_run = NULL,
- .cb_collect = in_serial_collect,
+ .cb_collect = cb_serial_collect,
.cb_flush_buf = NULL,
- .cb_exit = in_serial_exit
+ .cb_exit = cb_serial_exit
};
