]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Some fixes about malloc/Realloc and mem leak
authorSimo Sorce <idra@samba.org>
Sun, 5 Aug 2001 10:10:16 +0000 (10:10 +0000)
committerSimo Sorce <idra@samba.org>
Sun, 5 Aug 2001 10:10:16 +0000 (10:10 +0000)
thanks to andreas moroder

source/lib/messages.c
source/lib/util.c
source/lib/util_file.c

index 78cd3e22bc2353a66dd6518c738cfcb047389c9a..54f6321041aa809bb5407629ad3ac4f057227352 100644 (file)
@@ -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"));
+       }
 }
 
 /****************************************************************************
index 282e0e43fa08c0cd92ddb0a28e35ebe01d4f431c..86c93e5ad0e81ea7775c8ccef7bef9c70c009314 100644 (file)
@@ -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;
   }
 
index 01a8b1c3334e999f3b17aa7bebdab852d7ab9ddf..a92eb153335cd29644434babd4cee17348abd179 100644 (file)
@@ -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;