@@ -181,6 +181,13 @@ static int prepare_label_runtime(struct log_to_metrics_ctx *ctx)
181181 flb_free (ctx -> label_accessors );
182182 ctx -> label_accessors = NULL ;
183183 }
184+ if (ctx -> label_ras ) {
185+ for (i = 0 ; i < ctx -> label_counter ; i ++ ) {
186+ flb_ra_destroy (ctx -> label_ras [i ]);
187+ }
188+ flb_free (ctx -> label_ras );
189+ ctx -> label_ras = NULL ;
190+ }
184191 return -1 ;
185192}
186193
@@ -403,7 +410,7 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
403410 ctx -> label_keys = flb_calloc (ctx -> label_counter , sizeof (char * ));
404411 if (!ctx -> label_keys ) {
405412 flb_errno ();
406- return -1 ;
413+ goto error ;
407414 }
408415
409416 ctx -> label_accessors = flb_calloc (ctx -> label_counter , sizeof (char * ));
@@ -434,12 +441,12 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
434441 mk_list_foreach (head , & f_ins -> properties ) {
435442 kv = mk_list_entry (head , struct flb_kv , _head );
436443
437- if (counter > ctx -> label_counter ) {
438- flb_plg_error (ctx -> ins , "internal label counter overflow" );
439- return -1 ;
440- }
441-
442444 if (strcasecmp (kv -> key , "label_field" ) == 0 ) {
445+ if (counter >= ctx -> label_counter ) {
446+ flb_plg_error (ctx -> ins , "internal label counter overflow" );
447+ goto error ;
448+ }
449+
443450 /* name and accessor are the same string */
444451 ctx -> label_keys [counter ] = flb_strdup (kv -> val );
445452 if (!ctx -> label_keys [counter ]) {
@@ -454,11 +461,15 @@ static int set_labels(struct log_to_metrics_ctx *ctx,
454461 counter ++ ;
455462 }
456463 else if (strcasecmp (kv -> key , "add_label" ) == 0 ) {
464+ if (counter >= ctx -> label_counter ) {
465+ flb_plg_error (ctx -> ins , "internal label counter overflow" );
466+ goto error ;
467+ }
457468 split = flb_utils_split (kv -> val , ' ' , 1 );
458469 if (mk_list_size (split ) != 2 ) {
459470 flb_plg_error (ctx -> ins , "invalid label, expected name and key" );
460471 flb_utils_split_free (split );
461- return -1 ;
472+ goto error ;
462473 }
463474
464475 sentry = mk_list_entry_first (split , struct flb_split_entry , _head );
0 commit comments