aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-09 18:02:52 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-09 18:02:52 +0200
commit4984ca8380195e69970ca14cbb0bc2bafe808d5d (patch)
tree304847151d13b813ae3c7af02fd3cd5c1f611093 /src/namestore/test_namestore_api_zone_iteration_specific_zone.c
parent2cac1c7df7a50fdf9a3861d3f095eff9cfadc34a (diff)
downloadgnunet-4984ca8380195e69970ca14cbb0bc2bafe808d5d.tar.gz
gnunet-4984ca8380195e69970ca14cbb0bc2bafe808d5d.zip
fix crash on error in test logic on shutdown
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration_specific_zone.c')
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c111
1 files changed, 40 insertions, 71 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index 54cbe5472..0b137cc62 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -59,50 +59,15 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
59 59
60 60
61/** 61/**
62 * Re-establish the connection to the service. 62 * Handle timeout.
63 * 63 *
64 * @param cls handle to use to re-connect. 64 * @param cls handle to use to re-connect.
65 * @param tc scheduler context
66 */ 65 */
67static void 66static void
68endbadly (void *cls) 67endbadly (void *cls)
69{ 68{
70 if (NULL != zi) 69 endbadly_task = NULL;
71 { 70 GNUNET_SCHEDULER_shutdown ();
72 GNUNET_NAMESTORE_zone_iteration_stop (zi);
73 zi = NULL;
74 }
75 if (nsh != NULL)
76 GNUNET_NAMESTORE_disconnect (nsh);
77 nsh = NULL;
78
79 GNUNET_free_non_null(s_name_1);
80 GNUNET_free_non_null(s_name_2);
81 GNUNET_free_non_null(s_name_3);
82
83 if (s_rd_1 != NULL)
84 {
85 GNUNET_free ((void *)s_rd_1->data);
86 GNUNET_free (s_rd_1);
87 }
88 if (s_rd_2 != NULL)
89 {
90 GNUNET_free ((void *)s_rd_2->data);
91 GNUNET_free (s_rd_2);
92 }
93 if (s_rd_3 != NULL)
94 {
95 GNUNET_free ((void *)s_rd_3->data);
96 GNUNET_free (s_rd_3);
97 }
98
99 if (privkey != NULL)
100 GNUNET_free (privkey);
101 privkey = NULL;
102
103 if (privkey2 != NULL)
104 GNUNET_free (privkey2);
105 privkey2 = NULL;
106 res = 1; 71 res = 1;
107} 72}
108 73
@@ -115,21 +80,21 @@ end (void *cls)
115 GNUNET_NAMESTORE_zone_iteration_stop (zi); 80 GNUNET_NAMESTORE_zone_iteration_stop (zi);
116 zi = NULL; 81 zi = NULL;
117 } 82 }
118 83 if (NULL != endbadly_task)
119 if (endbadly_task != NULL)
120 { 84 {
121 GNUNET_SCHEDULER_cancel (endbadly_task); 85 GNUNET_SCHEDULER_cancel (endbadly_task);
122 endbadly_task = NULL; 86 endbadly_task = NULL;
123 } 87 }
124 88 if (NULL != privkey)
125 if (privkey != NULL) 89 {
126 GNUNET_free (privkey); 90 GNUNET_free (privkey);
127 privkey = NULL; 91 privkey = NULL;
128 92 }
129 if (privkey2 != NULL) 93 if (NULL != privkey2)
94 {
130 GNUNET_free (privkey2); 95 GNUNET_free (privkey2);
131 privkey2 = NULL; 96 privkey2 = NULL;
132 97 }
133 GNUNET_free (s_name_1); 98 GNUNET_free (s_name_1);
134 GNUNET_free (s_name_2); 99 GNUNET_free (s_name_2);
135 GNUNET_free (s_name_3); 100 GNUNET_free (s_name_3);
@@ -149,8 +114,10 @@ end (void *cls)
149 GNUNET_free (s_rd_3); 114 GNUNET_free (s_rd_3);
150 } 115 }
151 if (nsh != NULL) 116 if (nsh != NULL)
117 {
152 GNUNET_NAMESTORE_disconnect (nsh); 118 GNUNET_NAMESTORE_disconnect (nsh);
153 nsh = NULL; 119 nsh = NULL;
120 }
154} 121}
155 122
156 123
@@ -158,6 +125,7 @@ static void
158fail_cb (void *cls) 125fail_cb (void *cls)
159{ 126{
160 GNUNET_assert (0); 127 GNUNET_assert (0);
128 zi = NULL;
161} 129}
162 130
163 131
@@ -243,7 +211,8 @@ zone_proc (void *cls,
243 else 211 else
244 { 212 {
245 GNUNET_break (0); 213 GNUNET_break (0);
246 GNUNET_SCHEDULER_add_now (&end, NULL); 214 res = 2;
215 GNUNET_SCHEDULER_shutdown ();
247 } 216 }
248} 217}
249 218
@@ -251,24 +220,28 @@ zone_proc (void *cls,
251static void 220static void
252zone_proc_end (void *cls) 221zone_proc_end (void *cls)
253{ 222{
223 zi = NULL;
254 GNUNET_break (2 == returned_records); 224 GNUNET_break (2 == returned_records);
255 if (2 == returned_records) 225 if (2 == returned_records)
256 { 226 {
257 res = 0; /* Last iteraterator callback, we are done */ 227 res = 0; /* Last iteraterator callback, we are done */
258 zi = NULL;
259 } 228 }
260 else 229 else
230 {
261 res = 1; 231 res = 1;
232 }
262 233
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Received last result, iteration done after receing %u results\n", 235 "Received last result, iteration done after receing %u results\n",
265 returned_records); 236 returned_records);
266 GNUNET_SCHEDULER_add_now (&end, NULL); 237 GNUNET_SCHEDULER_shutdown ();
267} 238}
268 239
269 240
270static void 241static void
271put_cont (void *cls, int32_t success, const char *emsg) 242put_cont (void *cls,
243 int32_t success,
244 const char *emsg)
272{ 245{
273 static int c = 0; 246 static int c = 0;
274 247
@@ -284,9 +257,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
284 "Failed to created records: `%s'\n", 257 "Failed to created records: `%s'\n",
285 emsg); 258 emsg);
286 GNUNET_break (0); 259 GNUNET_break (0);
287 if (NULL != endbadly_task) 260 res = 2;
288 GNUNET_SCHEDULER_cancel (endbadly_task); 261 GNUNET_SCHEDULER_shutdown ();
289 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
290 return; 262 return;
291 } 263 }
292 264
@@ -309,9 +281,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "Failed to create zone iterator\n"); 282 "Failed to create zone iterator\n");
311 GNUNET_break (0); 283 GNUNET_break (0);
312 if (NULL != endbadly_task) 284 res = 2;
313 GNUNET_SCHEDULER_cancel (endbadly_task); 285 GNUNET_SCHEDULER_shutdown ();
314 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
315 return; 286 return;
316 } 287 }
317 } 288 }
@@ -321,11 +292,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
321static struct GNUNET_GNSRECORD_Data * 292static struct GNUNET_GNSRECORD_Data *
322create_record (unsigned int count) 293create_record (unsigned int count)
323{ 294{
324 unsigned int c; 295 struct GNUNET_GNSRECORD_Data *rd;
325 struct GNUNET_GNSRECORD_Data * rd;
326 296
327 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 297 rd = GNUNET_new_array (count,
328 for (c = 0; c < count; c++) 298 struct GNUNET_GNSRECORD_Data);
299 for (unsigned int c = 0; c < count; c++)
329 { 300 {
330 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 301 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
331 rd[c].record_type = 1111; 302 rd[c].record_type = 1111;
@@ -356,9 +327,8 @@ empty_zone_proc (void *cls,
356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
357 _("Expected empty zone but received zone private key\n")); 328 _("Expected empty zone but received zone private key\n"));
358 GNUNET_break (0); 329 GNUNET_break (0);
359 if (endbadly_task != NULL) 330 res = 2;
360 GNUNET_SCHEDULER_cancel (endbadly_task); 331 GNUNET_SCHEDULER_shutdown ();
361 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
362 return; 332 return;
363 } 333 }
364 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 334 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -366,9 +336,8 @@ empty_zone_proc (void *cls,
366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
367 _("Expected no zone content but received data\n")); 337 _("Expected no zone content but received data\n"));
368 GNUNET_break (0); 338 GNUNET_break (0);
369 if (endbadly_task != NULL) 339 res = 2;
370 GNUNET_SCHEDULER_cancel (endbadly_task); 340 GNUNET_SCHEDULER_shutdown ();
371 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
372 return; 341 return;
373 } 342 }
374 GNUNET_assert (0); 343 GNUNET_assert (0);
@@ -431,6 +400,8 @@ run (void *cls,
431 const struct GNUNET_CONFIGURATION_Handle *cfg, 400 const struct GNUNET_CONFIGURATION_Handle *cfg,
432 struct GNUNET_TESTING_Peer *peer) 401 struct GNUNET_TESTING_Peer *peer)
433{ 402{
403 GNUNET_SCHEDULER_add_shutdown (&end,
404 NULL);
434 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 405 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
435 &endbadly, 406 &endbadly,
436 NULL); 407 NULL);
@@ -450,9 +421,7 @@ run (void *cls,
450 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
451 "Failed to create zone iterator\n"); 422 "Failed to create zone iterator\n");
452 GNUNET_break (0); 423 GNUNET_break (0);
453 GNUNET_SCHEDULER_cancel (endbadly_task); 424 GNUNET_SCHEDULER_shutdown ();
454 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
455 NULL);
456 } 425 }
457} 426}
458 427