diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-26 15:51:56 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2015-03-26 15:51:56 +0000 |
commit | 726b28a61c858b4b251e4a0a006e4021b01886c0 (patch) | |
tree | 8b8d6dded055f1fefd2cee84dabb59dc889dcfe8 /src/rest | |
parent | 9982f58b45230373960cea1fe1fb294602bdd56d (diff) | |
download | gnunet-726b28a61c858b4b251e4a0a006e4021b01886c0.tar.gz gnunet-726b28a61c858b4b251e4a0a006e4021b01886c0.zip |
-fix mem corruption
Diffstat (limited to 'src/rest')
-rw-r--r-- | src/rest/gnunet-rest-server.c | 11 | ||||
-rw-r--r-- | src/rest/rest.c | 32 |
2 files changed, 23 insertions, 20 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 84fc69d02..aa95e48b3 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -292,7 +292,7 @@ create_response (void *cls, | |||
292 | } | 292 | } |
293 | if (NULL == con_handle->plugin) | 293 | if (NULL == con_handle->plugin) |
294 | { | 294 | { |
295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Queueing response with MHD\n"); | 296 | "Queueing response with MHD\n"); |
297 | GNUNET_free (con_handle); | 297 | GNUNET_free (con_handle); |
298 | return MHD_queue_response (con, | 298 | return MHD_queue_response (con, |
@@ -356,15 +356,6 @@ mhd_completed_cb (void *cls, | |||
356 | void **con_cls, | 356 | void **con_cls, |
357 | enum MHD_RequestTerminationCode toe) | 357 | enum MHD_RequestTerminationCode toe) |
358 | { | 358 | { |
359 | struct MhdConnectionHandle *con_handle; | ||
360 | |||
361 | con_handle = *con_cls; | ||
362 | if (NULL != con_handle) | ||
363 | { | ||
364 | MHD_destroy_response (con_handle->response); | ||
365 | GNUNET_free (con_handle); | ||
366 | *con_cls = NULL; | ||
367 | } | ||
368 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | 359 | if (MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) |
369 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
370 | "MHD encountered error handling request: %d\n", | 361 | "MHD encountered error handling request: %d\n", |
diff --git a/src/rest/rest.c b/src/rest/rest.c index d6fb8a2f3..f3251db1a 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c | |||
@@ -91,6 +91,8 @@ GNUNET_REST_jsonapi_resource_new (const char *type, const char *id) | |||
91 | return NULL; | 91 | return NULL; |
92 | 92 | ||
93 | res = GNUNET_new (struct JsonApiResource); | 93 | res = GNUNET_new (struct JsonApiResource); |
94 | res->prev = NULL; | ||
95 | res->next = NULL; | ||
94 | 96 | ||
95 | res->res_obj = json_object (); | 97 | res->res_obj = json_object (); |
96 | 98 | ||
@@ -236,6 +238,8 @@ add_json_resource (struct JsonApiObject *obj, | |||
236 | return; | 238 | return; |
237 | 239 | ||
238 | res = GNUNET_new (struct JsonApiResource); | 240 | res = GNUNET_new (struct JsonApiResource); |
241 | res->next = NULL; | ||
242 | res->prev = NULL; | ||
239 | res->res_obj = json_deep_copy (res_json); | 243 | res->res_obj = json_deep_copy (res_json); |
240 | GNUNET_REST_jsonapi_object_resource_add (obj, res); | 244 | GNUNET_REST_jsonapi_object_resource_add (obj, res); |
241 | } | 245 | } |
@@ -303,11 +307,18 @@ void | |||
303 | GNUNET_REST_jsonapi_object_delete (struct JsonApiObject *resp) | 307 | GNUNET_REST_jsonapi_object_delete (struct JsonApiObject *resp) |
304 | { | 308 | { |
305 | struct JsonApiResource *res; | 309 | struct JsonApiResource *res; |
310 | struct JsonApiResource *res_next; | ||
306 | 311 | ||
307 | for (res = resp->res_list_head; | 312 | for (res = resp->res_list_head; |
308 | res != NULL; | 313 | res != NULL;) |
309 | res = res->next) | 314 | { |
315 | GNUNET_CONTAINER_DLL_remove (resp->res_list_head, | ||
316 | resp->res_list_tail, | ||
317 | res); | ||
318 | res_next = res->next; | ||
310 | GNUNET_REST_jsonapi_resource_delete (res); | 319 | GNUNET_REST_jsonapi_resource_delete (res); |
320 | res = res_next; | ||
321 | } | ||
311 | GNUNET_free (resp); | 322 | GNUNET_free (resp); |
312 | } | 323 | } |
313 | 324 | ||
@@ -420,7 +431,7 @@ GNUNET_REST_jsonapi_data_serialize (const struct JsonApiObject *resp, | |||
420 | } | 431 | } |
421 | json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, res_arr); | 432 | json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, res_arr); |
422 | } | 433 | } |
423 | *result = json_dumps (root_json, JSON_COMPACT); | 434 | *result = json_dumps (root_json, JSON_INDENT(2)); |
424 | return GNUNET_OK; | 435 | return GNUNET_OK; |
425 | } | 436 | } |
426 | 437 | ||
@@ -454,14 +465,17 @@ GNUNET_REST_namespace_match (const char *url, const char *namespace) | |||
454 | * @param data JSON result | 465 | * @param data JSON result |
455 | * @retun MHD response | 466 | * @retun MHD response |
456 | */ | 467 | */ |
457 | struct MHD_Response* | 468 | struct MHD_Response* |
458 | GNUNET_REST_create_json_response (const char *data) | 469 | GNUNET_REST_create_json_response (const char *data) |
459 | { | 470 | { |
460 | struct MHD_Response *resp; | 471 | struct MHD_Response *resp; |
461 | size_t len; | 472 | size_t len; |
462 | 473 | ||
463 | if (NULL == data) | 474 | if (NULL == data) |
475 | { | ||
464 | len = 0; | 476 | len = 0; |
477 | data = ""; | ||
478 | } | ||
465 | else | 479 | else |
466 | len = strlen (data); | 480 | len = strlen (data); |
467 | resp = MHD_create_response_from_buffer (len, | 481 | resp = MHD_create_response_from_buffer (len, |
@@ -482,24 +496,22 @@ GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn, | |||
482 | char *url; | 496 | char *url; |
483 | 497 | ||
484 | count = 0; | 498 | count = 0; |
485 | |||
486 | while (NULL != handlers[count].method) | 499 | while (NULL != handlers[count].method) |
487 | count++; | 500 | count++; |
488 | 501 | ||
489 | GNUNET_asprintf (&url, "%s", conn->url); | 502 | GNUNET_asprintf (&url, "%s", conn->url); |
490 | if (url[strlen (url)-1] == '/') | 503 | if (url[strlen (url)-1] == '/') |
491 | url[strlen (url)-1] = '\0'; | 504 | url[strlen (url)-1] = '\0'; |
492 | |||
493 | for (i = 0; i < count; i++) | 505 | for (i = 0; i < count; i++) |
494 | { | 506 | { |
495 | if (0 != strcasecmp (conn->method, handlers[count].method)) | 507 | if (0 != strcasecmp (conn->method, handlers[i].method)) |
496 | break; | 508 | break; |
497 | if (strlen (url) < strlen (handlers[count].namespace)) | 509 | if (strlen (url) < strlen (handlers[i].namespace)) |
498 | break; | 510 | break; |
499 | if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[count].namespace)) | 511 | if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace)) |
500 | break; | 512 | break; |
501 | //Match | 513 | //Match |
502 | handlers[count].proc (conn, (const char*)url, cls); | 514 | handlers[i].proc (conn, (const char*)url, cls); |
503 | GNUNET_free (url); | 515 | GNUNET_free (url); |
504 | return GNUNET_YES; | 516 | return GNUNET_YES; |
505 | } | 517 | } |