From c4167baca1f8890a1fccce2273f1809def3d9703 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 Dec 2003 22:46:46 +0000 Subject: Get a little paranoid about memfree use in convert_string_allocate.. Looking at crash bugs #809 and others. Jeremy. (This used to be commit cd2075580b0f35c8a414c995f03834c01efaa9be) --- source3/lib/charcnv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 0a6a1fc75d..6a00402193 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -488,7 +488,6 @@ convert: } } - /** * Convert between character sets, allocating a new buffer using talloc for the result. * @@ -581,19 +580,19 @@ char *strdup_upper(const char *s) size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer; + smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, (void **) &buffer); - if (size == -1) { + if (size == -1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { - free(buffer); + SAFE_FREE(buffer); return srclen; } size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); - free(buffer); + SAFE_FREE(buffer); return size; } @@ -604,11 +603,11 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) char *strdup_lower(const char *s) { size_t size; - smb_ucs2_t *buffer; + smb_ucs2_t *buffer = NULL; char *out_buffer; size = push_ucs2_allocate(&buffer, s); - if (size == -1) { + if (size == -1 || !buffer) { return NULL; } -- cgit