From ddebde8638d3be9d1ebafbfde3396b2ae110e55c Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Fri, 23 Jan 2015 14:52:11 -0500 Subject: [PATCH] Use template for nullify to avoid aliasing issue. --- json_gssapi/test/command_mocks/InitSecContextMock.cpp | 8 ++++---- json_gssapi/test/command_mocks/InitSecContextMock.h | 14 +++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/json_gssapi/test/command_mocks/InitSecContextMock.cpp b/json_gssapi/test/command_mocks/InitSecContextMock.cpp index 568d63c..aa64344 100644 --- a/json_gssapi/test/command_mocks/InitSecContextMock.cpp +++ b/json_gssapi/test/command_mocks/InitSecContextMock.cpp @@ -31,9 +31,9 @@ void InitSecContextMock::reset() { retVal = 0; minor_status = 0; - nullify((void **)&claimant_cred_handle); - nullify((void **)&context_handle); - nullify((void **)&target_name); + nullify(claimant_cred_handle); + nullify(context_handle); + nullify(target_name); // Our current handling of OIDs means attempting to free one // will often result in a double-free or an attempt to free // a constant OID. For now, it is better to occasionally leak. @@ -41,7 +41,7 @@ void InitSecContextMock::reset() mech_type = GSS_C_NO_OID; req_flags = 0; time_req = 0; - nullify((void **)&input_chan_bindings); + nullify(input_chan_bindings); input_token.length = 0; input_token.value = NULL; actual_mech_type = GSS_C_NO_OID; diff --git a/json_gssapi/test/command_mocks/InitSecContextMock.h b/json_gssapi/test/command_mocks/InitSecContextMock.h index f26a2c5..e97dfb3 100644 --- a/json_gssapi/test/command_mocks/InitSecContextMock.h +++ b/json_gssapi/test/command_mocks/InitSecContextMock.h @@ -33,17 +33,13 @@ public: static bool visited; static bool invalidContextHandle; - static void nullify(void **ptr) + template + static void nullify(t *&ptr) { - if (!ptr) + if (ptr) { - std::cout << std::endl << "Nullify called with a void ** that is NULL at the top level" << std::endl; - return; - } - if (*ptr) - { - free(*ptr); - *ptr = NULL; + free(ptr); + ptr = NULL; } } -- 2.1.4