2525#include <fluent-bit/flb_jsmn.h>
2626#include <fluent-bit/flb_output_plugin.h>
2727#include <fluent-bit/flb_utils.h>
28+ #include <fluent-bit/flb_log.h>
29+ #include <fluent-bit/flb_mem.h>
2830
2931#include <stdlib.h>
3032#include <time.h>
@@ -377,22 +379,18 @@ struct flb_aws_provider *flb_iot_provider_create(struct flb_config *config,
377379 implementation -> client -> static_headers = & implementation -> thing_name_header ;
378380 implementation -> client -> static_headers_len = 1 ;
379381
380- /* Clean up temporary variables */
381- flb_sds_destroy (protocol );
382- flb_sds_destroy (host );
383- flb_sds_destroy (port_sds );
384- flb_sds_destroy (endpoint_path );
385-
386- return provider ;
387-
388- error :
389- flb_aws_provider_destroy (provider );
390- flb_sds_destroy (protocol );
391- flb_sds_destroy (host );
392- flb_sds_destroy (port_sds );
393- flb_sds_destroy (endpoint_path );
394- return NULL ;
395- }
382+ goto cleanup ; // At the end of the func
383+ error :
384+ flb_aws_provider_destroy (provider );
385+ provider = NULL ;
386+ // if no return it just keep executing :)
387+ cleanup :
388+ flb_sds_destroy (protocol );
389+ flb_sds_destroy (host );
390+ flb_sds_destroy (port_sds );
391+ flb_sds_destroy (endpoint_path );
392+ return provider ;
393+ }
396394
397395static int iot_credentials_request (struct flb_aws_provider_iot * implementation )
398396{
@@ -648,4 +646,4 @@ static struct flb_aws_credentials *flb_parse_iot_credentials(char *response, siz
648646 flb_aws_credentials_destroy (creds );
649647 flb_free (tokens );
650648 return NULL ;
651- }
649+ }
0 commit comments