@@ -279,6 +279,8 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins,
279279 flb_errno ();
280280 return NULL ;
281281 }
282+ mk_list_init (& ctx -> global_metadata_fields );
283+ mk_list_init (& ctx -> log_event_metadata_fields );
282284
283285 ctx -> ins = ins ;
284286
@@ -298,8 +300,8 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins,
298300 return NULL ;
299301 }
300302 }
303+
301304 if (ctx -> oci_la_global_metadata != NULL ) {
302- mk_list_init (& ctx -> global_metadata_fields );
303305 ret = global_metadata_fields_create (ctx );
304306 if (ret != 0 ) {
305307 flb_errno ();
@@ -309,7 +311,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins,
309311 }
310312
311313 if (ctx -> oci_la_metadata != NULL ) {
312- mk_list_init (& ctx -> log_event_metadata_fields );
313314 ret = log_event_metadata_create (ctx );
314315 if (ret != 0 ) {
315316 flb_errno ();
@@ -435,16 +436,24 @@ static void metadata_fields_destroy(struct flb_oci_logan *ctx)
435436
436437 mk_list_foreach_safe (head , tmp , & ctx -> global_metadata_fields ) {
437438 f = mk_list_entry (head , struct metadata_obj , _head );
438- flb_sds_destroy (f -> key );
439- flb_sds_destroy (f -> val );
439+ if (f -> key ) {
440+ flb_sds_destroy (f -> key );
441+ }
442+ if (f -> val ) {
443+ flb_sds_destroy (f -> val );
444+ }
440445 mk_list_del (& f -> _head );
441446 flb_free (f );
442447 }
443448
444449 mk_list_foreach_safe (head , tmp , & ctx -> log_event_metadata_fields ) {
445450 f = mk_list_entry (head , struct metadata_obj , _head );
446- flb_sds_destroy (f -> key );
447- flb_sds_destroy (f -> val );
451+ if (f -> key ) {
452+ flb_sds_destroy (f -> key );
453+ }
454+ if (f -> val ) {
455+ flb_sds_destroy (f -> val );
456+ }
448457 mk_list_del (& f -> _head );
449458 flb_free (f );
450459 }
0 commit comments