Use template for nullify to avoid aliasing issue.
authorSam Hartman <hartmans@debian.org>
Fri, 23 Jan 2015 19:52:11 +0000 (14:52 -0500)
committerSam Hartman <hartmans@debian.org>
Fri, 22 May 2015 18:39:34 +0000 (14:39 -0400)
json_gssapi/test/command_mocks/InitSecContextMock.cpp
json_gssapi/test/command_mocks/InitSecContextMock.h

index 568d63c..aa64344 100644 (file)
@@ -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;
index f26a2c5..e97dfb3 100644 (file)
@@ -33,17 +33,13 @@ public:
   static bool                   visited;
   static bool                   invalidContextHandle;
   
-  static void nullify(void **ptr)
+  template <class t>
+    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;
     }
   }