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>
3133#include <string.h>
3234#include <sys/types.h>
3335#include <sys/stat.h>
3436
35- /* IoT Credentials Environment Variables */
36- #define AWS_IOT_KEY_FILE "AWS_IOT_KEY_FILE"
37- #define AWS_IOT_CERT_FILE "AWS_IOT_CERT_FILE"
38- #define AWS_IOT_CA_CERT_FILE "AWS_IOT_CA_CERT_FILE"
39- #define AWS_IOT_CREDENTIALS_ENDPOINT "AWS_IOT_CREDENTIALS_ENDPOINT"
40- #define AWS_IOT_THING_NAME "AWS_IOT_THING_NAME"
41- #define AWS_IOT_ROLE_ALIAS "AWS_IOT_ROLE_ALIAS"
42-
4337/* IoT Provider */
4438struct flb_aws_provider_iot {
4539 struct flb_aws_credentials * creds ;
@@ -377,22 +371,18 @@ struct flb_aws_provider *flb_iot_provider_create(struct flb_config *config,
377371 implementation -> client -> static_headers = & implementation -> thing_name_header ;
378372 implementation -> client -> static_headers_len = 1 ;
379373
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- }
374+ goto cleanup ; // At the end of the func
375+ error :
376+ flb_aws_provider_destroy (provider );
377+ provider = NULL ;
378+ // if no return it just keep executing :)
379+ cleanup :
380+ flb_sds_destroy (protocol );
381+ flb_sds_destroy (host );
382+ flb_sds_destroy (port_sds );
383+ flb_sds_destroy (endpoint_path );
384+ return provider ;
385+ }
396386
397387static int iot_credentials_request (struct flb_aws_provider_iot * implementation )
398388{
@@ -648,4 +638,4 @@ static struct flb_aws_credentials *flb_parse_iot_credentials(char *response, siz
648638 flb_aws_credentials_destroy (creds );
649639 flb_free (tokens );
650640 return NULL ;
651- }
641+ }
0 commit comments