From: Greg Hudson Date: Mon, 10 Sep 2012 16:28:09 +0000 (-0400) Subject: Add zapfreestr() helper to k5-int.h X-Git-Tag: krb5-1.11-alpha1~195 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0633f8317017a7d3ac4ac94c2321d20362f33653;p=thirdparty%2Fkrb5.git 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. --- 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) */