out_flowcounter: add missing memory allocation validation
@@ -53,16 +53,15 @@ static int configure(struct flb_out_fcount_config *ctx,
struct flb_output_instance *ins,
struct flb_config *config)
{
- const char* pval = NULL;
int i;
time_t base = time(NULL);
+ const char* pval = NULL;
/* default */
ctx->unit = FLB_UNIT_MIN;
ctx->tick = 60;
pval = flb_output_get_property("unit", ins);
-
if (pval != NULL) {
/* check unit of duration */
if (!strcasecmp(pval, FLB_UNIT_SEC)) {
@@ -97,6 +96,11 @@ static int configure(struct flb_out_fcount_config *ctx,
ctx->buf = (struct flb_out_fcount_buffer *)
flb_malloc(sizeof(struct flb_out_fcount_buffer)*ctx->size);
+ if (!ctx->buf) {
+ flb_errno();
+ return -1;
+ }
+
for (i = 0; i < ctx->size; i++) {
ctx->buf[i].until = base + ctx->tick*i;
count_initialized(&ctx->buf[i]);
