From e485a1a4986c9328754b9a8b3054b8a6738b54f0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 5 Aug 2001 10:10:16 +0000 Subject: Some fixes about malloc/Realloc and mem leak thanks to andreas moroder (This used to be commit b29a549cdd85d42a1697041ab04f0ae4eddd23ca) --- source3/lib/messages.c | 15 +++++++++++---- source3/lib/util.c | 2 +- source3/lib/util_file.c | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 78cd3e22bc..54f6321041 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -322,12 +322,19 @@ void message_register(int msg_type, dfn = (struct dispatch_fns *)malloc(sizeof(*dfn)); - ZERO_STRUCTP(dfn); + if (dfn != NULL) { - dfn->msg_type = msg_type; - dfn->fn = fn; + ZERO_STRUCTPN(dfn); - DLIST_ADD(dispatch_fns, dfn); + dfn->msg_type = msg_type; + dfn->fn = fn; + + DLIST_ADD(dispatch_fns, dfn); + } + else { + + DEBUG(0,("message_register: Not enough memory. malloc failed!\n")); + } } /**************************************************************************** diff --git a/source3/lib/util.c b/source3/lib/util.c index 282e0e43fa..86c93e5ad0 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -524,7 +524,7 @@ SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen, } while (!buf && size>0) { - buf = (char *)Realloc(buf,size+8); + buf = (char *)malloc(buf,size+8); if (!buf) size /= 2; } diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 01a8b1c333..a92eb15333 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -282,13 +282,15 @@ char *fgets_slash(char *s2,int maxlen,FILE *f) if (feof(f)) return(NULL); + if (maxlen <2) return(NULL); + if (!s2) { maxlen = MIN(maxlen,8); s = (char *)Realloc(s,maxlen); } - if (!s || maxlen < 2) return(NULL); + if (!s) return(NULL); *s = 0; -- cgit