From 0633f8317017a7d3ac4ac94c2321d20362f33653 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 10 Sep 2012 12:28:09 -0400 Subject: 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 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/include/k5-int.h b/src/include/k5-int.h index d119d02be4..670915d741 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) */ -- cgit