r4291 *alloc fix problems

Albert Chin samba-technical at mlists.thewrittenword.com
Tue Dec 21 03:45:58 GMT 2004


Some of the *alloc fixes in r4291 for source/lib/util_smbd.c and
source/lib/sysacls.c are incorrect.

$ svn diff -r4290:4291 source/lib/util_smbd.c
Index: source/lib/util_smbd.c
===================================================================
--- source/lib/util_smbd.c	(revision 4290)
+++ source/lib/util_smbd.c	(revision 4291)
@@ -45,7 +45,7 @@
 	int i;
 
 	max_grp = groups_max();
-	temp_groups = (gid_t *)malloc(sizeof(gid_t) * max_grp);
+	temp_groups = SMB_MALLOC_P(gid_t, max_grp);
                      ^^^^^^^^^^^^ Should be SMB_MALLOC_ARRAY
 	if (! temp_groups) {
 		return False;
 	}
@@ -54,7 +54,7 @@
 		
 		gid_t *groups_tmp;
 		
-		groups_tmp = Realloc(temp_groups, sizeof(gid_t) * max_grp);
+		groups_tmp = SMB_REALLOC(temp_groups, gid_t, max_grp);
                             ^^^^^^^^^^^ Should be SMB_REALLOC_ARRAY
 		
 		if (!groups_tmp) {
 			SAFE_FREE(temp_groups);

$ svn diff -r4290:4291 source/lib/sysacls.c
Index: source/lib/sysacls.c
===================================================================
--- source/lib/sysacls.c	(revision 4290)
+++ source/lib/sysacls.c	(revision 4291)
@@ -722,7 +722,7 @@
 	 * acl[] array, this actually allocates an ACL with room
 	 * for (count+1) entries
 	 */
-	if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
+	if ((a = SMB_MALLOC(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
                            ^^^^^^^^^^ Can be changed to:
                                         sizeof(struct SMB_ACL_T)
 		errno = ENOMEM;
 		return NULL;
 	}
@@ -1353,7 +1353,7 @@
 	 * acl[] array, this actually allocates an ACL with room
 	 * for (count+1) entries
 	 */
-	if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
+	if ((a = SMB_MALLOC(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
                            ^^^^^^^^^^ Can be changed to:
                                         sizeof(struct SMB_ACL_T)
 		errno = ENOMEM;
 		return NULL;
 	}
@@ -1982,7 +1982,7 @@
 {
 	SMB_ACL_T	a;
 
-	if ((a = malloc(sizeof(*a))) == NULL) {
+	if ((a = SMB_MALLOC_P(SMB_ACL_T)) == NULL) {
                              ^^^^^^^^^ Should be "struct SMB_ACL_T".
                                        SMB_ACL_T is a pointer to
                                        "struct SMB_ACL_T".
 		errno = ENOMEM;
 		return NULL;
 	}
@@ -1999,7 +1999,7 @@
 {
 	SMB_ACL_T	a;
 
-	if ((a = malloc(sizeof(*a))) == NULL) {
+	if ((a = SMB_MALLOC_P(SMB_ACL_T)) == NULL) {
                              ^^^^^^^^^ Should be "struct SMB_ACL_T".
                                        SMB_ACL_T is a pointer to
                                        "struct SMB_ACL_T".
 		errno = ENOMEM;
 		return NULL;
 	}
@@ -2056,7 +2056,7 @@
 		return NULL;
 	}
 
-	if ((a = malloc(sizeof(*a) + sizeof(struct acl))) == NULL) {
+	if ((a = SMB_MALLOC_P(struct acl)) == NULL) {
                              ^^^^^^^^^ Should be:
                                          sizeof(struct SMB_ACL_T) + sizeof(struct acl)
 		errno = ENOMEM;
 		return NULL;
 	}

-- 
albert chin (china at thewrittenword.com)


More information about the samba-technical mailing list