summaryrefslogtreecommitdiff
path: root/source3/param
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2001-08-08 16:54:16 +0000
committerSimo Sorce <idra@samba.org>2001-08-08 16:54:16 +0000
commit2f844bf447a98b802daa4b8d552ea4530e7f6108 (patch)
tree7beda0672e5fcc15125a7643d4d5fdef6f02b49e /source3/param
parent0897979a8b0976e03a84ccaf6a70cbaa62bbd195 (diff)
downloadsamba-2f844bf447a98b802daa4b8d552ea4530e7f6108.tar.gz
samba-2f844bf447a98b802daa4b8d552ea4530e7f6108.tar.bz2
samba-2f844bf447a98b802daa4b8d552ea4530e7f6108.zip
Change all realloc() statements to Realloc() (ecxept for tdb.c)
changed some code to exploit the fact that Realloc(NULL, size) == malloc(size) fixed some possible mem leaks, or seg faults. thanks to andreas moroder (mallocs not checked in client/client.c, client/smbumount.c) (This used to be commit 7f33c01688b825ab2fa9bbb2730bff4f2fa352be)
Diffstat (limited to 'source3/param')
-rw-r--r--source3/param/loadparm.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 6b3ded8c60..f3e3dcc31c 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -3585,25 +3585,17 @@ char **lp_list_make(char *string)
return NULL;
}
- list = (char**)malloc(((sizeof(char**)) * P_LIST_ABS));
- if (!list) {
- DEBUG(0,("ERROR: Unable to allocate memory"));
- free (s);
- return NULL;
- }
- memset (list, 0, ((sizeof(char**)) * P_LIST_ABS));
- lsize = P_LIST_ABS;
-
- num = 0;
+ num = lsize = 0;
+ list = NULL;
str = s;
while (*str)
{
if (!next_token(&str, tok, LIST_SEP, sizeof(pstring))) continue;
- if ((num +1) == lsize) {
+ if (num == lsize) {
lsize += P_LIST_ABS;
- rlist = (char **)realloc(list, ((sizeof(char **)) * lsize));
+ rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
if (!rlist) {
DEBUG(0,("ERROR: Unable to allocate memory"));
lp_list_free (&list);
@@ -3611,7 +3603,7 @@ char **lp_list_make(char *string)
return NULL;
}
else list = rlist;
- memset (&list[num], 0, ((sizeof(char**)) * P_LIST_ABS));
+ memset (&list[num], 0, ((sizeof(char**)) * (P_LIST_ABS +1)));
}
list[num] = strdup(tok);
@@ -3637,26 +3629,21 @@ BOOL lp_list_copy(char ***dest, char **src)
*dest = NULL;
if (!src) return False;
- list = (char**)malloc(((sizeof(char**)) * P_LIST_ABS));
- if (!list) {
- DEBUG(0,("ERROR: Unable to allocate memory"));
- return False;
- }
- memset (list, 0, ((sizeof(char**)) * P_LIST_ABS));
- lsize = P_LIST_ABS;
+ num = lsize = 0;
+ list = NULL;
- for (num = 0; src[num]; num++)
+ while (src[num])
{
- if ((num +1) == lsize) {
+ if (num == lsize) {
lsize += P_LIST_ABS;
- rlist = (char **)realloc(list, ((sizeof(char **)) * lsize));
+ rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
if (!rlist) {
DEBUG(0,("ERROR: Unable to allocate memory"));
lp_list_free (&list);
return False;
}
else list = rlist;
- memset (&list[num], 0, ((sizeof(char**)) * P_LIST_ABS));
+ memset (&list[num], 0, ((sizeof(char **)) * (P_LIST_ABS +1)));
}
list[num] = strdup(src[num]);
@@ -3665,6 +3652,8 @@ BOOL lp_list_copy(char ***dest, char **src)
lp_list_free (&list);
return False;
}
+
+ num++;
}
*dest = list;
@@ -3758,4 +3747,3 @@ BOOL lp_list_substitute(char **list, const char *pattern, const char *insert)
return True;
}
-