diff options
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | coreutils/date.c | 2 | ||||
-rw-r--r-- | coreutils/dd.c | 6 | ||||
-rw-r--r-- | coreutils/tr.c | 5 | ||||
-rw-r--r-- | date.c | 2 | ||||
-rw-r--r-- | dd.c | 6 | ||||
-rw-r--r-- | dmesg.c | 2 | ||||
-rw-r--r-- | fsck_minix.c | 35 | ||||
-rw-r--r-- | mkfs_minix.c | 10 | ||||
-rw-r--r-- | mkswap.c | 6 | ||||
-rw-r--r-- | sfdisk.c | 3 | ||||
-rw-r--r-- | tr.c | 5 | ||||
-rw-r--r-- | umount.c | 3 | ||||
-rw-r--r-- | util-linux/dmesg.c | 2 | ||||
-rw-r--r-- | util-linux/fsck_minix.c | 35 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 10 | ||||
-rw-r--r-- | util-linux/mkswap.c | 6 | ||||
-rw-r--r-- | util-linux/umount.c | 3 | ||||
-rw-r--r-- | utility.c | 18 |
19 files changed, 47 insertions, 115 deletions
@@ -52,6 +52,9 @@ | |||
52 | to match the terminal (defaults to width=79 when this is off). | 52 | to match the terminal (defaults to width=79 when this is off). |
53 | * Fixed mount'ing loop devices when the filesystem type was not | 53 | * Fixed mount'ing loop devices when the filesystem type was not |
54 | specified. It used to revert to non-loop after the first try. | 54 | specified. It used to revert to non-loop after the first try. |
55 | * all mallocs now use xmalloc (and so are OOM error safe), and | ||
56 | the common error handling saves a few bytes. Thanks to | ||
57 | Bob Tinsley <bob@earthrise.demon.co.uk> for the patch. | ||
55 | 58 | ||
56 | 59 | ||
57 | -Erik Andersen | 60 | -Erik Andersen |
diff --git a/coreutils/date.c b/coreutils/date.c index b4c3e7153..652db8d74 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -276,7 +276,7 @@ int date_main(int argc, char **argv) | |||
276 | } | 276 | } |
277 | 277 | ||
278 | /* Print OUTPUT (after ALL that!) */ | 278 | /* Print OUTPUT (after ALL that!) */ |
279 | t_buff = malloc(201); | 279 | t_buff = xmalloc(201); |
280 | strftime(t_buff, 200, date_fmt, &tm_time); | 280 | strftime(t_buff, 200, date_fmt, &tm_time); |
281 | printf("%s\n", t_buff); | 281 | printf("%s\n", t_buff); |
282 | 282 | ||
diff --git a/coreutils/dd.c b/coreutils/dd.c index 0d5b3e8ab..f40dec712 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -114,11 +114,7 @@ extern int dd_main(int argc, char **argv) | |||
114 | argv++; | 114 | argv++; |
115 | } | 115 | } |
116 | 116 | ||
117 | buf = malloc(blockSize); | 117 | buf = xmalloc(blockSize); |
118 | if (buf == NULL) { | ||
119 | fprintf(stderr, "Cannot allocate buffer\n"); | ||
120 | exit(FALSE); | ||
121 | } | ||
122 | 118 | ||
123 | intotal = 0; | 119 | intotal = 0; |
124 | outTotal = 0; | 120 | outTotal = 0; |
diff --git a/coreutils/tr.c b/coreutils/tr.c index 8ac09e641..3bfa48080 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c | |||
@@ -44,7 +44,7 @@ static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; | |||
44 | #endif | 44 | #endif |
45 | static const char rcsid[] = | 45 | static const char rcsid[] = |
46 | 46 | ||
47 | "$Id: tr.c,v 1.1 2000/03/05 08:07:00 erik Exp $"; | 47 | "$Id: tr.c,v 1.2 2000/03/21 22:32:57 erik Exp $"; |
48 | #endif /* not lint */ | 48 | #endif /* not lint */ |
49 | #endif /* #if 0 */ | 49 | #endif /* #if 0 */ |
50 | 50 | ||
@@ -433,8 +433,7 @@ STR *s; | |||
433 | "unknown class %s", | 433 | "unknown class %s", |
434 | s->str); | 434 | s->str); |
435 | 435 | ||
436 | if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL) | 436 | cp->set = p = xmalloc((NCHARS + 1) * sizeof(int)); |
437 | errx(1, "malloc"); | ||
438 | bzero(p, (NCHARS + 1) * sizeof(int)); | 437 | bzero(p, (NCHARS + 1) * sizeof(int)); |
439 | 438 | ||
440 | for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) | 439 | for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) |
@@ -276,7 +276,7 @@ int date_main(int argc, char **argv) | |||
276 | } | 276 | } |
277 | 277 | ||
278 | /* Print OUTPUT (after ALL that!) */ | 278 | /* Print OUTPUT (after ALL that!) */ |
279 | t_buff = malloc(201); | 279 | t_buff = xmalloc(201); |
280 | strftime(t_buff, 200, date_fmt, &tm_time); | 280 | strftime(t_buff, 200, date_fmt, &tm_time); |
281 | printf("%s\n", t_buff); | 281 | printf("%s\n", t_buff); |
282 | 282 | ||
@@ -114,11 +114,7 @@ extern int dd_main(int argc, char **argv) | |||
114 | argv++; | 114 | argv++; |
115 | } | 115 | } |
116 | 116 | ||
117 | buf = malloc(blockSize); | 117 | buf = xmalloc(blockSize); |
118 | if (buf == NULL) { | ||
119 | fprintf(stderr, "Cannot allocate buffer\n"); | ||
120 | exit(FALSE); | ||
121 | } | ||
122 | 118 | ||
123 | intotal = 0; | 119 | intotal = 0; |
124 | outTotal = 0; | 120 | outTotal = 0; |
@@ -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/fsck_minix.c b/fsck_minix.c index cfa973ecf..47e81ce42 100644 --- a/fsck_minix.c +++ b/fsck_minix.c | |||
@@ -603,23 +603,13 @@ static void read_superblock(void) | |||
603 | 603 | ||
604 | static void read_tables(void) | 604 | static 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/mkfs_minix.c b/mkfs_minix.c index 4435cb64a..1ee3d4cfa 100644 --- a/mkfs_minix.c +++ b/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); |
@@ -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) { |
@@ -300,8 +300,7 @@ static struct sector *get_sector(char *dev, int fd, unsigned long sno) | |||
300 | if (!sseek(dev, fd, sno)) | 300 | if (!sseek(dev, fd, sno)) |
301 | return 0; | 301 | return 0; |
302 | 302 | ||
303 | if (!(s = (struct sector *) malloc(sizeof(struct sector)))) | 303 | s = (struct sector *) xmalloc(sizeof(struct sector)); |
304 | fatalError("out of memory - giving up\n"); | ||
305 | 304 | ||
306 | if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) { | 305 | if (read(fd, s->data, sizeof(s->data)) != sizeof(s->data)) { |
307 | perror("read"); | 306 | perror("read"); |
@@ -44,7 +44,7 @@ static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; | |||
44 | #endif | 44 | #endif |
45 | static const char rcsid[] = | 45 | static const char rcsid[] = |
46 | 46 | ||
47 | "$Id: tr.c,v 1.1 2000/03/05 08:07:00 erik Exp $"; | 47 | "$Id: tr.c,v 1.2 2000/03/21 22:32:57 erik Exp $"; |
48 | #endif /* not lint */ | 48 | #endif /* not lint */ |
49 | #endif /* #if 0 */ | 49 | #endif /* #if 0 */ |
50 | 50 | ||
@@ -433,8 +433,7 @@ STR *s; | |||
433 | "unknown class %s", | 433 | "unknown class %s", |
434 | s->str); | 434 | s->str); |
435 | 435 | ||
436 | if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL) | 436 | cp->set = p = xmalloc((NCHARS + 1) * sizeof(int)); |
437 | errx(1, "malloc"); | ||
438 | bzero(p, (NCHARS + 1) * sizeof(int)); | 437 | bzero(p, (NCHARS + 1) * sizeof(int)); |
439 | 438 | ||
440 | for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) | 439 | for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) |
@@ -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; |
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 | ||
604 | static void read_tables(void) | 604 | static 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; |
@@ -172,9 +172,7 @@ void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) | |||
172 | 172 | ||
173 | i = hash_inode(statbuf->st_ino); | 173 | i = hash_inode(statbuf->st_ino); |
174 | s = name ? strlen(name) : 0; | 174 | s = name ? strlen(name) : 0; |
175 | bucket = malloc(sizeof(ino_dev_hashtable_bucket_t) + s); | 175 | bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s); |
176 | if (bucket == NULL) | ||
177 | fatalError("Not enough memory."); | ||
178 | bucket->ino = statbuf->st_ino; | 176 | bucket->ino = statbuf->st_ino; |
179 | bucket->dev = statbuf->st_dev; | 177 | bucket->dev = statbuf->st_dev; |
180 | if (name) | 178 | if (name) |
@@ -1003,7 +1001,7 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, | |||
1003 | if (strcmp(needle, newNeedle) == 0) | 1001 | if (strcmp(needle, newNeedle) == 0) |
1004 | return FALSE; | 1002 | return FALSE; |
1005 | 1003 | ||
1006 | oldhayStack = (char *) malloc((unsigned) (strlen(haystack))); | 1004 | oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack))); |
1007 | while (where != NULL) { | 1005 | while (where != NULL) { |
1008 | foundOne++; | 1006 | foundOne++; |
1009 | strcpy(oldhayStack, haystack); | 1007 | strcpy(oldhayStack, haystack); |
@@ -1364,22 +1362,16 @@ extern pid_t findPidByName( char* pidName) | |||
1364 | #endif /* BB_FEATURE_USE_DEVPS_PATCH */ | 1362 | #endif /* BB_FEATURE_USE_DEVPS_PATCH */ |
1365 | #endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ | 1363 | #endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ |
1366 | 1364 | ||
1367 | #if defined BB_GUNZIP \ | 1365 | /* this should really be farmed out to libbusybox.a */ |
1368 | || defined BB_GZIP \ | ||
1369 | || defined BB_PRINTF \ | ||
1370 | || defined BB_TAIL | ||
1371 | extern void *xmalloc(size_t size) | 1366 | extern void *xmalloc(size_t size) |
1372 | { | 1367 | { |
1373 | void *cp = malloc(size); | 1368 | void *cp = malloc(size); |
1374 | 1369 | ||
1375 | if (cp == NULL) { | 1370 | if (cp == NULL) |
1376 | errorMsg("out of memory"); | 1371 | fatalError("out of memory"); |
1377 | } | ||
1378 | return cp; | 1372 | return cp; |
1379 | } | 1373 | } |
1380 | 1374 | ||
1381 | #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ | ||
1382 | |||
1383 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) | 1375 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) |
1384 | extern int vdprintf(int d, const char *format, va_list ap) | 1376 | extern int vdprintf(int d, const char *format, va_list ap) |
1385 | { | 1377 | { |