|
26 | 26 | #include "fw_conn.h" |
27 | 27 | #include "fw_config.h" |
28 | 28 |
|
| 29 | +static void fw_destory_shared_key(struct flb_in_fw_config *config) |
| 30 | +{ |
| 31 | + if (config->owns_shared_key && config->shared_key) { |
| 32 | + flb_sds_destroy(config->shared_key); |
| 33 | + } |
| 34 | + |
| 35 | + config->shared_key = NULL; |
| 36 | + config->owns_shared_key = FLB_FALSE; |
| 37 | +} |
| 38 | + |
| 39 | +static int fw_create_empty_shared_key(struct flb_in_fw_config *config, |
| 40 | + struct flb_input_instance *i_ins) |
| 41 | +{ |
| 42 | + flb_sds_t empty_key = flb_sds_create(""); |
| 43 | + if (!empty_key) { |
| 44 | + flb_plg_error(i_ins, "empty shared_key alloc failed"); |
| 45 | + return -1; |
| 46 | + } |
| 47 | + else { |
| 48 | + if (config->owns_shared_key && config->shared_key) { |
| 49 | + flb_sds_destroy(config->shared_key); |
| 50 | + } |
| 51 | + config->shared_key = empty_key; |
| 52 | + config->owns_shared_key = FLB_TRUE; |
| 53 | + } |
| 54 | + |
| 55 | + return 0; |
| 56 | +} |
| 57 | + |
29 | 58 | struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins) |
30 | 59 | { |
31 | 60 | char tmp[16]; |
@@ -87,10 +116,9 @@ struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins) |
87 | 116 |
|
88 | 117 | /* Shared Key */ |
89 | 118 | if (config->empty_shared_key) { |
90 | | - if (config->shared_key) { |
91 | | - flb_sds_destroy(config->shared_key); |
| 119 | + if (fw_create_empty_shared_key(config, i_ins) == -1) { |
| 120 | + return NULL; |
92 | 121 | } |
93 | | - config->shared_key = flb_sds_create(""); |
94 | 122 | } |
95 | 123 |
|
96 | 124 | /* Self Hostname */ |
@@ -131,7 +159,7 @@ int fw_config_destroy(struct flb_in_fw_config *config) |
131 | 159 | flb_free(config->tcp_port); |
132 | 160 | } |
133 | 161 |
|
134 | | - flb_sds_destroy(config->shared_key); |
| 162 | + fw_destory_shared_key(config); |
135 | 163 | flb_sds_destroy(config->self_hostname); |
136 | 164 |
|
137 | 165 | flb_free(config); |
|
0 commit comments