svn commit: r278921 - head/usr.bin/du

Pedro F. Giffuni pfg at FreeBSD.org
Tue Feb 17 21:12:46 UTC 2015


Author: pfg
Date: Tue Feb 17 21:12:45 2015
New Revision: 278921
URL: https://svnweb.freebsd.org/changeset/base/278921

Log:
  du(1): replace malloc + memset with calloc.

Modified:
  head/usr.bin/du/du.c

Modified: head/usr.bin/du/du.c
==============================================================================
--- head/usr.bin/du/du.c	Tue Feb 17 20:52:51 2015	(r278920)
+++ head/usr.bin/du/du.c	Tue Feb 17 21:12:45 2015	(r278921)
@@ -376,7 +376,7 @@ linkchk(FTSENT *p)
 	/* If the hash table is getting too full, enlarge it. */
 	if (number_entries > number_buckets * 10 && !stop_allocating) {
 		new_size = number_buckets * 2;
-		new_buckets = malloc(new_size * sizeof(struct links_entry *));
+		new_buckets = calloc(new_size, sizeof(struct links_entry *));
 
 		/* Try releasing the free list to see if that helps. */
 		if (new_buckets == NULL && free_list != NULL) {
@@ -385,16 +385,13 @@ linkchk(FTSENT *p)
 				free_list = le->next;
 				free(le);
 			}
-			new_buckets = malloc(new_size *
-			    sizeof(new_buckets[0]));
+			new_buckets = calloc(new_size, sizeof(new_buckets[0]));
 		}
 
 		if (new_buckets == NULL) {
 			stop_allocating = 1;
 			warnx("No more memory for tracking hard links");
 		} else {
-			memset(new_buckets, 0,
-			    new_size * sizeof(struct links_entry *));
 			for (i = 0; i < number_buckets; i++) {
 				while (buckets[i] != NULL) {
 					/* Remove entry from old bucket. */


More information about the svn-src-all mailing list