krb5 commit: Add zapfreestr() helper to k5-int.h

Greg Hudson ghudson at MIT.EDU
Mon Sep 10 12:28:31 EDT 2012


https://github.com/krb5/krb5/commit/0633f8317017a7d3ac4ac94c2321d20362f33653
commit 0633f8317017a7d3ac4ac94c2321d20362f33653
Author: Greg Hudson <ghudson at mit.edu>
Date:   Mon Sep 10 12:28:09 2012 -0400

    Add zapfreestr() helper to k5-int.h
    
    Since zapfree(str, strlen(str)) won't work for possibly-null values of
    str, add a helper zapfreestr() which only calls strlen() if the string
    value is non-null.

 src/include/k5-int.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index d119d02..670915d 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -675,6 +675,16 @@ zapfree(void *ptr, size_t len)
     }
 }
 
+/* Convenience function: zap and free zero-terminated str if it is non-NULL. */
+static inline void
+zapfreestr(void *str)
+{
+    if (str != NULL) {
+        zap(str, strlen((char *)str));
+        free(str);
+    }
+}
+
 /*
  * Combine two keys (normally used by the hardware preauth mechanism)
  */


More information about the cvs-krb5 mailing list