]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add zapfreestr() helper to k5-int.h
authorGreg Hudson <ghudson@mit.edu>
Mon, 10 Sep 2012 16:28:09 +0000 (12:28 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 10 Sep 2012 16:28:09 +0000 (12:28 -0400)
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

index d119d02be4a9049d97473ddb9976ef50ec948e58..670915d741dd4f2fa5131d492bfd65fb99c08071 100644 (file)
@@ -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)
  */