Update destroys to return void. Assert failure in context destroy. Update tests

This commit is contained in:
Neel Goyal 2014-03-11 11:43:41 -04:00
parent 02d318a8ea
commit 501bc14de6
7 changed files with 19 additions and 25 deletions

View File

@ -43,6 +43,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <unbound.h> #include <unbound.h>
#include <assert.h>
#include "context.h" #include "context.h"
#include "types-internal.h" #include "types-internal.h"
@ -532,19 +533,17 @@ getdns_context_create(struct getdns_context ** context, int set_from_os)
* Call this to dispose of resources associated with a context once you * Call this to dispose of resources associated with a context once you
* are done with it. * are done with it.
*/ */
getdns_return_t void
getdns_context_destroy(struct getdns_context *context) getdns_context_destroy(struct getdns_context *context)
{ {
if (context == NULL) { if (context == NULL) {
return GETDNS_RETURN_INVALID_PARAMETER; return;
} }
// If being destroyed during getdns callback, // If being destroyed during getdns callback,
// return an error // fail via assert
if (context->processing > 0) { assert(context->processing == 0);
return GETDNS_RETURN_INVALID_PARAMETER;
}
if (context->destroying) { if (context->destroying) {
return GETDNS_RETURN_BAD_CONTEXT; return ;
} }
context->destroying = 1; context->destroying = 1;
cancel_outstanding_requests(context, 1); cancel_outstanding_requests(context, 1);
@ -582,7 +581,6 @@ getdns_context_destroy(struct getdns_context *context)
GETDNS_FREE(context->my_mf, context->timeouts_by_time); GETDNS_FREE(context->my_mf, context->timeouts_by_time);
GETDNS_FREE(context->my_mf, context); GETDNS_FREE(context->my_mf, context);
return GETDNS_RETURN_GOOD;
} /* getdns_context_destroy */ } /* getdns_context_destroy */
/* /*

View File

@ -373,16 +373,15 @@ getdns_dict_item_free(ldns_rbnode_t * node, void *arg)
} /* getdns_dict_item_free */ } /* getdns_dict_item_free */
/*---------------------------------------- getdns_dict_destroy */ /*---------------------------------------- getdns_dict_destroy */
getdns_return_t void
getdns_dict_destroy(struct getdns_dict *dict) getdns_dict_destroy(struct getdns_dict *dict)
{ {
if (!dict) if (!dict)
return GETDNS_RETURN_INVALID_PARAMETER; return;
ldns_traverse_postorder(&(dict->root), ldns_traverse_postorder(&(dict->root),
getdns_dict_item_free, dict); getdns_dict_item_free, dict);
GETDNS_FREE(dict->mf, dict); GETDNS_FREE(dict->mf, dict);
return GETDNS_RETURN_GOOD;
} /* getdns_dict_destroy */ } /* getdns_dict_destroy */
/*---------------------------------------- getdns_dict_set_dict */ /*---------------------------------------- getdns_dict_set_dict */

View File

@ -649,7 +649,7 @@ getdns_list *getdns_list_create_with_extended_memory_functions(
* you MUST copy those instances BEFORE you destroy the list else * you MUST copy those instances BEFORE you destroy the list else
* unpleasant things will happen at run-time * unpleasant things will happen at run-time
*/ */
getdns_return_t getdns_list_destroy(getdns_list *this_list); void getdns_list_destroy(getdns_list *this_list);
/** /**
* assign the child_dict to an item in a parent list, the parent list copies * assign the child_dict to an item in a parent list, the parent list copies
@ -716,7 +716,7 @@ getdns_dict *getdns_dict_create_with_extended_memory_functions(
* be aware that if you have fetched any data from the dictionary it will * be aware that if you have fetched any data from the dictionary it will
* no longer be available (you are likely to experience bad things if you try) * no longer be available (you are likely to experience bad things if you try)
*/ */
getdns_return_t getdns_dict_destroy(getdns_dict *this_dict); void getdns_dict_destroy(getdns_dict *this_dict);
getdns_return_t getdns_dict_set_dict(getdns_dict *this_dict, getdns_return_t getdns_dict_set_dict(getdns_dict *this_dict,
const char *name, const getdns_dict *child_dict); const char *name, const getdns_dict *child_dict);
@ -815,7 +815,7 @@ getdns_context_create_with_extended_memory_functions(
void (*free) (void *userarg, void *) void (*free) (void *userarg, void *)
); );
getdns_return_t getdns_context_destroy(getdns_context *context); void getdns_context_destroy(getdns_context *context);
getdns_return_t getdns_return_t
getdns_cancel_callback(getdns_context *context, getdns_cancel_callback(getdns_context *context,

View File

@ -323,13 +323,13 @@ getdns_list_destroy_item(struct getdns_list *list, size_t index)
} }
/*---------------------------------------- getdns_list_destroy */ /*---------------------------------------- getdns_list_destroy */
getdns_return_t void
getdns_list_destroy(struct getdns_list *list) getdns_list_destroy(struct getdns_list *list)
{ {
size_t i; size_t i;
if (!list) if (!list)
return GETDNS_RETURN_INVALID_PARAMETER; return;
for (i = 0; i < list->numinuse; i++) for (i = 0; i < list->numinuse; i++)
getdns_list_destroy_item(list, i); getdns_list_destroy_item(list, i);
@ -337,7 +337,6 @@ getdns_list_destroy(struct getdns_list *list)
if (list->items) if (list->items)
GETDNS_FREE(list->mf, list->items); GETDNS_FREE(list->mf, list->items);
GETDNS_FREE(list->mf, list); GETDNS_FREE(list->mf, list);
return GETDNS_RETURN_GOOD;
} /* getdns_list_destroy */ } /* getdns_list_destroy */
/*---------------------------------------- getdns_list_add_item */ /*---------------------------------------- getdns_list_add_item */

View File

@ -266,8 +266,7 @@ void destroy_callbackfn(struct getdns_context *context,
int* flag = (int*)userarg; int* flag = (int*)userarg;
*flag = 1; *flag = 1;
getdns_dict_destroy(response); getdns_dict_destroy(response);
ck_assert_msg(getdns_context_destroy(context) != GETDNS_RETURN_GOOD, getdns_context_destroy(context);
"Expected getdns_context_destroy to not succeed");
} }
/* /*

View File

@ -86,9 +86,7 @@
* destroy the current context. * destroy the current context.
*/ */
#define CONTEXT_DESTROY \ #define CONTEXT_DESTROY \
ASSERT_RC(getdns_context_destroy(context), \ getdns_context_destroy(context);
GETDNS_RETURN_GOOD, \
"Return code from getdns_context_destroy()");
/* /*
* The EVENT_BASE_CREATE macro is used to * The EVENT_BASE_CREATE macro is used to

View File

@ -294,9 +294,10 @@
tcase_add_test(tc_pos, getdns_context_destroy_4); tcase_add_test(tc_pos, getdns_context_destroy_4);
tcase_add_test(tc_pos, getdns_context_destroy_5); tcase_add_test(tc_pos, getdns_context_destroy_5);
tcase_add_test(tc_pos, getdns_context_destroy_6); tcase_add_test(tc_pos, getdns_context_destroy_6);
tcase_add_test(tc_pos, getdns_context_destroy_7); // raise aborts via assertion failures
tcase_add_test(tc_pos, getdns_context_destroy_8); tcase_add_test_raise_signal(tc_pos, getdns_context_destroy_7, SIGABRT);
tcase_add_test(tc_pos, getdns_context_destroy_9); tcase_add_test_raise_signal(tc_pos, getdns_context_destroy_8, SIGABRT);
tcase_add_test_raise_signal(tc_pos, getdns_context_destroy_9, SIGABRT);
suite_add_tcase(s, tc_pos); suite_add_tcase(s, tc_pos);
return s; return s;