aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorerik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-03-21 22:32:57 +0000
committererik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-03-21 22:32:57 +0000
commitd67b2b05efca2a57f7f25e521450c200ef38803e (patch)
treeaf12b114d51e9ae7a8753baf09feb9ab8d654f26 /util-linux
parentcfe2ce6d7262d074b6fe0c1dea4d96df37e8a9ef (diff)
downloadbusybox-w32-d67b2b05efca2a57f7f25e521450c200ef38803e.tar.gz
busybox-w32-d67b2b05efca2a57f7f25e521450c200ef38803e.tar.bz2
busybox-w32-d67b2b05efca2a57f7f25e521450c200ef38803e.zip
* all mallocs now use xmalloc (and so are OOM error safe), and
the common error handling saves a few bytes. Thanks to Bob Tinsley <bob@earthrise.demon.co.uk> for the patch. -Erik git-svn-id: svn://busybox.net/trunk/busybox@416 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/dmesg.c2
-rw-r--r--util-linux/fsck_minix.c35
-rw-r--r--util-linux/mkfs_minix.c10
-rw-r--r--util-linux/mkswap.c6
-rw-r--r--util-linux/umount.c3
5 files changed, 15 insertions, 41 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index bbed8221a..2bbf43a12 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -95,7 +95,7 @@ int dmesg_main(int argc, char **argv)
95 95
96 if (bufsize < 4096) 96 if (bufsize < 4096)
97 bufsize = 4096; 97 bufsize = 4096;
98 buf = (char *) malloc(bufsize); 98 buf = (char *) xmalloc(bufsize);
99 n = klogctl(cmd, buf, bufsize); 99 n = klogctl(cmd, buf, bufsize);
100 if (n < 0) { 100 if (n < 0) {
101 goto klogctl_error; 101 goto klogctl_error;
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c
index cfa973ecf..47e81ce42 100644
--- a/util-linux/fsck_minix.c
+++ b/util-linux/fsck_minix.c
@@ -603,23 +603,13 @@ static void read_superblock(void)
603 603
604static void read_tables(void) 604static void read_tables(void)
605{ 605{
606 inode_map = malloc(IMAPS * BLOCK_SIZE); 606 inode_map = xmalloc(IMAPS * BLOCK_SIZE);
607 if (!inode_map) 607 zone_map = xmalloc(ZMAPS * BLOCK_SIZE);
608 die("Unable to allocate buffer for inode map");
609 zone_map = malloc(ZMAPS * BLOCK_SIZE);
610 if (!inode_map)
611 die("Unable to allocate buffer for zone map");
612 memset(inode_map, 0, sizeof(inode_map)); 608 memset(inode_map, 0, sizeof(inode_map));
613 memset(zone_map, 0, sizeof(zone_map)); 609 memset(zone_map, 0, sizeof(zone_map));
614 inode_buffer = malloc(INODE_BUFFER_SIZE); 610 inode_buffer = xmalloc(INODE_BUFFER_SIZE);
615 if (!inode_buffer) 611 inode_count = xmalloc(INODES + 1);
616 die("Unable to allocate buffer for inodes"); 612 zone_count = xmalloc(ZONES);
617 inode_count = malloc(INODES + 1);
618 if (!inode_count)
619 die("Unable to allocate buffer for inode count");
620 zone_count = malloc(ZONES);
621 if (!zone_count)
622 die("Unable to allocate buffer for zone count");
623 if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) 613 if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
624 die("Unable to read inode map"); 614 die("Unable to read inode map");
625 if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) 615 if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
@@ -1247,18 +1237,9 @@ static void alloc_name_list(void)
1247{ 1237{
1248 int i; 1238 int i;
1249 1239
1250 name_list = malloc(sizeof(char *) * MAX_DEPTH); 1240 name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
1251 if (!name_list) { 1241 for (i = 0; i < MAX_DEPTH; i++)
1252 fprintf(stderr,"fsck_minix: name_list: %s\n", strerror(errno)); 1242 name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
1253 exit(1);
1254 }
1255 for (i = 0; i < MAX_DEPTH; i++) {
1256 name_list[i] = malloc(sizeof(char) * PATH_MAX + 1);
1257 if (!name_list[i]) {
1258 fprintf(stderr,"fsck_minix: name_list: %s\n", strerror(errno));
1259 exit(1);
1260 }
1261 }
1262} 1243}
1263 1244
1264/* execute this atexit() to deallocate name_list[] */ 1245/* execute this atexit() to deallocate name_list[] */
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 4435cb64a..1ee3d4cfa 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -530,19 +530,15 @@ static void setup_tables(void)
530 die("unable to allocate buffers for maps"); 530 die("unable to allocate buffers for maps");
531 } 531 }
532 FIRSTZONE = NORM_FIRSTZONE; 532 FIRSTZONE = NORM_FIRSTZONE;
533 inode_map = malloc(IMAPS * BLOCK_SIZE); 533 inode_map = xmalloc(IMAPS * BLOCK_SIZE);
534 zone_map = malloc(ZMAPS * BLOCK_SIZE); 534 zone_map = xmalloc(ZMAPS * BLOCK_SIZE);
535 if (!inode_map || !zone_map)
536 die("unable to allocate buffers for maps");
537 memset(inode_map, 0xff, IMAPS * BLOCK_SIZE); 535 memset(inode_map, 0xff, IMAPS * BLOCK_SIZE);
538 memset(zone_map, 0xff, ZMAPS * BLOCK_SIZE); 536 memset(zone_map, 0xff, ZMAPS * BLOCK_SIZE);
539 for (i = FIRSTZONE; i < ZONES; i++) 537 for (i = FIRSTZONE; i < ZONES; i++)
540 unmark_zone(i); 538 unmark_zone(i);
541 for (i = MINIX_ROOT_INO; i <= INODES; i++) 539 for (i = MINIX_ROOT_INO; i <= INODES; i++)
542 unmark_inode(i); 540 unmark_inode(i);
543 inode_buffer = malloc(INODE_BUFFER_SIZE); 541 inode_buffer = xmalloc(INODE_BUFFER_SIZE);
544 if (!inode_buffer)
545 die("unable to allocate buffer for inodes");
546 memset(inode_buffer, 0, INODE_BUFFER_SIZE); 542 memset(inode_buffer, 0, INODE_BUFFER_SIZE);
547 printf("%ld inodes\n", INODES); 543 printf("%ld inodes\n", INODES);
548 printf("%ld blocks\n", ZONES); 544 printf("%ld blocks\n", ZONES);
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 130d24162..17866a735 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -116,7 +116,7 @@ static void init_signature_page()
116 if (pagesize != PAGE_SIZE) 116 if (pagesize != PAGE_SIZE)
117 fprintf(stderr, "Assuming pages of size %d\n", pagesize); 117 fprintf(stderr, "Assuming pages of size %d\n", pagesize);
118#endif 118#endif
119 signature_page = (int *) malloc(pagesize); 119 signature_page = (int *) xmalloc(pagesize);
120 memset(signature_page, 0, pagesize); 120 memset(signature_page, 0, pagesize);
121 p = (struct swap_header_v1 *) signature_page; 121 p = (struct swap_header_v1 *) signature_page;
122} 122}
@@ -230,9 +230,7 @@ void check_blocks(void)
230 int do_seek = 1; 230 int do_seek = 1;
231 char *buffer; 231 char *buffer;
232 232
233 buffer = malloc(pagesize); 233 buffer = xmalloc(pagesize);
234 if (!buffer)
235 die("Out of memory");
236 current_page = 0; 234 current_page = 0;
237 while (current_page < PAGES) { 235 while (current_page < PAGES) {
238 if (!check) { 236 if (!check) {
diff --git a/util-linux/umount.c b/util-linux/umount.c
index b0f393cca..6661db878 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -89,8 +89,7 @@ void mtab_read(void)
89 return; 89 return;
90 } 90 }
91 while ((e = getmntent(fp))) { 91 while ((e = getmntent(fp))) {
92 entry = malloc(sizeof(struct _mtab_entry_t)); 92 entry = xmalloc(sizeof(struct _mtab_entry_t));
93
94 entry->device = strdup(e->mnt_fsname); 93 entry->device = strdup(e->mnt_fsname);
95 entry->mountpt = strdup(e->mnt_dir); 94 entry->mountpt = strdup(e->mnt_dir);
96 entry->next = mtab_cache; 95 entry->next = mtab_cache;