summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/snprintf.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c
index 3034dfaaf6..2733626108 100644
--- a/source3/lib/snprintf.c
+++ b/source3/lib/snprintf.c
@@ -100,6 +100,11 @@
#define LLONG long
#endif
+/* free memory if the pointer is valid and zero the pointer */
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0)
+#endif
+
static size_t dopr(char *buffer, size_t maxlen, const char *format,
va_list args);
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
@@ -822,10 +827,10 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
{
char *msg = NULL;
vasprintf(&msg, format, arglist);
- if (!msg)
- return;
- syslog(facility_priority, "%s", msg);
- free(msg);
+ if (!msg)
+ return;
+ syslog(facility_priority, "%s", msg);
+ SAFE_FREE(msg);
}
#endif /* HAVE_SYSLOG */
#endif /* HAVE_VSYSLOG */