diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-10 12:32:40 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-10 12:32:40 +0000 |
commit | f06baa8a2c99545167142049f19f4a7bedfe1764 (patch) | |
tree | 185d0bba4ddd80c6c186183bc1cdf8d85815023c /src/my/test_my.c | |
parent | 2f1634060e7d4aab5ff046ca50f1e21bae7471fb (diff) | |
download | gnunet-f06baa8a2c99545167142049f19f4a7bedfe1764.tar.gz gnunet-f06baa8a2c99545167142049f19f4a7bedfe1764.zip |
finish to fix memory leak
Diffstat (limited to 'src/my/test_my.c')
-rw-r--r-- | src/my/test_my.c | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/my/test_my.c b/src/my/test_my.c index a375a76fa..5f778ad46 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_mysql_lib.h" | 28 | #include "gnunet_mysql_lib.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | 30 | ||
31 | |||
31 | /** | 32 | /** |
32 | * Run actual test queries. | 33 | * Run actual test queries. |
33 | * | 34 | * |
@@ -77,7 +78,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
77 | 78 | ||
78 | memset (&hc, 0, sizeof(hc)); | 79 | memset (&hc, 0, sizeof(hc)); |
79 | memset (&hc2, 0, sizeof(hc2)); | 80 | memset (&hc2, 0, sizeof(hc2)); |
80 | 81 | ||
81 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 82 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
82 | "INSERT INTO test_my2 (" | 83 | "INSERT INTO test_my2 (" |
83 | " pub" | 84 | " pub" |
@@ -139,28 +140,28 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
139 | } | 140 | } |
140 | 141 | ||
141 | struct GNUNET_MY_QueryParam params_select[] = { | 142 | struct GNUNET_MY_QueryParam params_select[] = { |
142 | GNUNET_MY_query_param_end | 143 | GNUNET_MY_query_param_end |
143 | }; | 144 | }; |
144 | 145 | ||
145 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | 146 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, |
146 | statements_handle_select, | 147 | statements_handle_select, |
147 | params_select)) | 148 | params_select)) |
148 | { | 149 | { |
149 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); | 150 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); |
150 | return 1; | 151 | return 1; |
151 | } | 152 | } |
152 | 153 | ||
153 | struct GNUNET_MY_ResultSpec results_select[] = { | 154 | struct GNUNET_MY_ResultSpec results_select[] = { |
154 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | 155 | GNUNET_MY_result_spec_rsa_public_key (&pub2), |
155 | GNUNET_MY_result_spec_rsa_signature (&sig2), | 156 | GNUNET_MY_result_spec_rsa_signature (&sig2), |
156 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 157 | GNUNET_MY_result_spec_absolute_time (&abs_time2), |
157 | GNUNET_MY_result_spec_absolute_time (&forever2), | 158 | GNUNET_MY_result_spec_absolute_time (&forever2), |
158 | GNUNET_MY_result_spec_auto_from_type (&hc2), | 159 | GNUNET_MY_result_spec_auto_from_type (&hc2), |
159 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | 160 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), |
160 | GNUNET_MY_result_spec_uint16 (&u162), | 161 | GNUNET_MY_result_spec_uint16 (&u162), |
161 | GNUNET_MY_result_spec_uint32 (&u322), | 162 | GNUNET_MY_result_spec_uint32 (&u322), |
162 | GNUNET_MY_result_spec_uint64 (&u642), | 163 | GNUNET_MY_result_spec_uint64 (&u642), |
163 | GNUNET_MY_result_spec_end | 164 | GNUNET_MY_result_spec_end |
164 | }; | 165 | }; |
165 | 166 | ||
166 | ret = GNUNET_MY_extract_result (statements_handle_select, | 167 | ret = GNUNET_MY_extract_result (statements_handle_select, |
@@ -177,17 +178,18 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
177 | GNUNET_assert (NULL != sig2); | 178 | GNUNET_assert (NULL != sig2); |
178 | GNUNET_assert (NULL != pub2); | 179 | GNUNET_assert (NULL != pub2); |
179 | GNUNET_break (0 == | 180 | GNUNET_break (0 == |
180 | GNUNET_CRYPTO_rsa_signature_cmp (sig, | 181 | GNUNET_CRYPTO_rsa_signature_cmp (sig, |
181 | sig2)); | 182 | sig2)); |
182 | GNUNET_break (0 == | 183 | GNUNET_break (0 == |
183 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, | 184 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, |
184 | pub2)); | 185 | pub2)); |
185 | 186 | ||
186 | GNUNET_break (strlen (msg) == msg2_len); | 187 | GNUNET_break (strlen (msg) == msg2_len); |
187 | GNUNET_break (0 == | 188 | GNUNET_break (0 == |
188 | strncmp (msg, | 189 | strncmp (msg, |
189 | msg2, | 190 | msg2, |
190 | msg2_len)); | 191 | msg2_len)); |
192 | |||
191 | GNUNET_break (16 == u162); | 193 | GNUNET_break (16 == u162); |
192 | GNUNET_break (32 == u322); | 194 | GNUNET_break (32 == u322); |
193 | GNUNET_break (64 == u642); | 195 | GNUNET_break (64 == u642); |
@@ -199,7 +201,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
199 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 201 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
200 | 202 | ||
201 | if (GNUNET_OK != ret) | 203 | if (GNUNET_OK != ret) |
202 | return 1; | 204 | return 1; |
203 | 205 | ||
204 | return 0; | 206 | return 0; |
205 | } | 207 | } |
@@ -212,46 +214,47 @@ main (int argc, const char * const argv[]) | |||
212 | struct GNUNET_MYSQL_Context *context = NULL; | 214 | struct GNUNET_MYSQL_Context *context = NULL; |
213 | int ret; | 215 | int ret; |
214 | 216 | ||
215 | GNUNET_log_setup ( "test-my", | 217 | GNUNET_log_setup ("test-my", |
216 | "WARNING", | 218 | "WARNING", |
217 | NULL); | 219 | NULL); |
218 | 220 | ||
219 | config = GNUNET_CONFIGURATION_create (); | 221 | config = GNUNET_CONFIGURATION_create (); |
220 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) | 222 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) |
221 | { | 223 | { |
222 | fprintf (stderr, "Failed to parse configuaration\n"); | 224 | fprintf (stderr, "Failed to parse configuaration\n"); |
223 | return 1; | 225 | return 1; |
224 | } | 226 | } |
225 | 227 | ||
226 | context = GNUNET_MYSQL_context_create (config, | 228 | context = GNUNET_MYSQL_context_create (config, |
227 | "datastore-mysql"); | 229 | "datastore-mysql"); |
228 | if (NULL == context) | 230 | if (NULL == context) |
229 | { | 231 | { |
230 | fprintf(stderr, "Failed to connect to database\n"); | 232 | fprintf(stderr, "Failed to connect to database\n"); |
231 | return 77; | 233 | return 77; |
232 | } | 234 | } |
233 | 235 | ||
234 | (void) GNUNET_MYSQL_statement_run (context, | 236 | (void) GNUNET_MYSQL_statement_run (context, |
235 | "DROP TABLE test_my2;"); | 237 | "DROP TABLE test_my2;"); |
238 | |||
236 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 239 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
237 | "CREATE TABLE IF NOT EXISTS test_my2(" | 240 | "CREATE TABLE IF NOT EXISTS test_my2(" |
238 | " pub BLOB NOT NULL" | 241 | " pub BLOB NOT NULL" |
239 | ",sig BLOB NOT NULL" | 242 | ",sig BLOB NOT NULL" |
240 | ",abs_time BIGINT NOT NULL" | 243 | ",abs_time BIGINT NOT NULL" |
241 | ",forever BIGINT NOT NULL" | 244 | ",forever BIGINT NOT NULL" |
242 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" | 245 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" |
243 | ",vsize BLOB NOT NULL" | 246 | ",vsize BLOB NOT NULL" |
244 | ",u16 SMALLINT NOT NULL" | 247 | ",u16 SMALLINT NOT NULL" |
245 | ",u32 INT NOT NULL" | 248 | ",u32 INT NOT NULL" |
246 | ",u64 BIGINT NOT NULL" | 249 | ",u64 BIGINT NOT NULL" |
247 | ")")) | 250 | ")")) |
248 | { | 251 | { |
249 | fprintf (stderr, | 252 | fprintf (stderr, |
250 | "Failed to create table \n"); | 253 | "Failed to create table \n"); |
251 | GNUNET_MYSQL_statements_invalidate (context); | 254 | GNUNET_MYSQL_statements_invalidate (context); |
252 | GNUNET_MYSQL_context_destroy (context); | 255 | GNUNET_MYSQL_context_destroy (context); |
253 | 256 | ||
254 | return 1; | 257 | return 1; |
255 | } | 258 | } |
256 | 259 | ||
257 | ret = run_queries (context); | 260 | ret = run_queries (context); |