aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-08 09:07:50 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-08 09:07:50 +0100
commit9037787eaee5efb58fd46f326397193b16b161dd (patch)
treedfd0e7d93faf711ca7dcf8c7fe0abfb21082e3d3
parentef3817c6dcbf9270d36b48a0547e507221abce74 (diff)
downloadbusybox-w32-9037787eaee5efb58fd46f326397193b16b161dd.tar.gz
busybox-w32-9037787eaee5efb58fd46f326397193b16b161dd.tar.bz2
busybox-w32-9037787eaee5efb58fd46f326397193b16b161dd.zip
*: fix places where we were still using malloc/realloc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--e2fsprogs/old_e2fsprogs/ext2fs/ext2fs_inline.c4
-rw-r--r--e2fsprogs/old_e2fsprogs/fsck.c8
-rw-r--r--editors/ed.c19
-rw-r--r--editors/sed.c2
-rw-r--r--networking/libiproute/ipaddress.c42
5 files changed, 29 insertions, 46 deletions
diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs_inline.c b/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs_inline.c
index da1cf5be5..b9aab440a 100644
--- a/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs_inline.c
+++ b/e2fsprogs/old_e2fsprogs/ext2fs/ext2fs_inline.c
@@ -50,9 +50,7 @@ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
50 /* Use "memcpy" for pointer assignments here to avoid problems 50 /* Use "memcpy" for pointer assignments here to avoid problems
51 * with C99 strict type aliasing rules. */ 51 * with C99 strict type aliasing rules. */
52 memcpy(&p, ptr, sizeof (p)); 52 memcpy(&p, ptr, sizeof (p));
53 p = realloc(p, size); 53 p = xrealloc(p, size);
54 if (!p)
55 return EXT2_ET_NO_MEMORY;
56 memcpy(ptr, &p, sizeof (p)); 54 memcpy(ptr, &p, sizeof (p));
57 return 0; 55 return 0;
58} 56}
diff --git a/e2fsprogs/old_e2fsprogs/fsck.c b/e2fsprogs/old_e2fsprogs/fsck.c
index 687938c24..c0964f79d 100644
--- a/e2fsprogs/old_e2fsprogs/fsck.c
+++ b/e2fsprogs/old_e2fsprogs/fsck.c
@@ -377,8 +377,7 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
377{ 377{
378 struct fs_info *fs; 378 struct fs_info *fs;
379 379
380 if (!(fs = malloc(sizeof(struct fs_info)))) 380 fs = xmalloc(sizeof(struct fs_info));
381 return NULL;
382 381
383 fs->device = string_copy(device); 382 fs->device = string_copy(device);
384 fs->mountpt = string_copy(mntpnt); 383 fs->mountpt = string_copy(mntpnt);
@@ -573,10 +572,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
573 struct fsck_instance *inst, *p; 572 struct fsck_instance *inst, *p;
574 pid_t pid; 573 pid_t pid;
575 574
576 inst = malloc(sizeof(struct fsck_instance)); 575 inst = xzalloc(sizeof(struct fsck_instance));
577 if (!inst)
578 return ENOMEM;
579 memset(inst, 0, sizeof(struct fsck_instance));
580 576
581 prog = xasprintf("fsck.%s", type); 577 prog = xasprintf("fsck.%s", type);
582 argv[0] = prog; 578 argv[0] = prog;
diff --git a/editors/ed.c b/editors/ed.c
index 9ce8bead1..516b8d78d 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -454,11 +454,7 @@ static void subCommand(const char *cmd, int num1, int num2)
454 * structure and use that. Link it in in place of 454 * structure and use that. Link it in in place of
455 * the old line structure. 455 * the old line structure.
456 */ 456 */
457 nlp = malloc(sizeof(LINE) + lp->len + deltaLen); 457 nlp = xmalloc(sizeof(LINE) + lp->len + deltaLen);
458 if (nlp == NULL) {
459 bb_error_msg("can't get memory for line");
460 return;
461 }
462 458
463 nlp->len = lp->len + deltaLen; 459 nlp->len = lp->len + deltaLen;
464 460
@@ -712,12 +708,7 @@ static int readLines(const char *file, int num)
712 708
713 if (bufUsed >= bufSize) { 709 if (bufUsed >= bufSize) {
714 len = (bufSize * 3) / 2; 710 len = (bufSize * 3) / 2;
715 cp = realloc(bufBase, len); 711 cp = xrealloc(bufBase, len);
716 if (cp == NULL) {
717 bb_error_msg("no memory for buffer");
718 close(fd);
719 return FALSE;
720 }
721 bufBase = cp; 712 bufBase = cp;
722 bufPtr = bufBase + bufUsed; 713 bufPtr = bufBase + bufUsed;
723 bufSize = len; 714 bufSize = len;
@@ -872,11 +863,7 @@ static int insertLine(int num, const char *data, int len)
872 return FALSE; 863 return FALSE;
873 } 864 }
874 865
875 newLp = malloc(sizeof(LINE) + len - 1); 866 newLp = xmalloc(sizeof(LINE) + len - 1);
876 if (newLp == NULL) {
877 bb_error_msg("failed to allocate memory for line");
878 return FALSE;
879 }
880 867
881 memcpy(newLp->data, data, len); 868 memcpy(newLp->data, data, len);
882 newLp->len = len; 869 newLp->len = len;
diff --git a/editors/sed.c b/editors/sed.c
index 19e768355..fd9dd1be6 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1094,7 +1094,7 @@ static void process_files(void)
1094 /* append next_line, read new next_line. */ 1094 /* append next_line, read new next_line. */
1095 } 1095 }
1096 len = strlen(pattern_space); 1096 len = strlen(pattern_space);
1097 pattern_space = realloc(pattern_space, len + strlen(next_line) + 2); 1097 pattern_space = xrealloc(pattern_space, len + strlen(next_line) + 2);
1098 pattern_space[len] = '\n'; 1098 pattern_space[len] = '\n';
1099 strcpy(pattern_space + len+1, next_line); 1099 strcpy(pattern_space + len+1, next_line);
1100 last_gets_char = next_gets_char; 1100 last_gets_char = next_gets_char;
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index c450c6a9f..03f5073fb 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -97,9 +97,8 @@ static void print_queuelen(char *name)
97static NOINLINE int print_linkinfo(const struct nlmsghdr *n) 97static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
98{ 98{
99 struct ifinfomsg *ifi = NLMSG_DATA(n); 99 struct ifinfomsg *ifi = NLMSG_DATA(n);
100 struct rtattr * tb[IFLA_MAX+1]; 100 struct rtattr *tb[IFLA_MAX+1];
101 int len = n->nlmsg_len; 101 int len = n->nlmsg_len;
102 unsigned m_flag = 0;
103 102
104 if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) 103 if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
105 return 0; 104 return 0;
@@ -130,22 +129,27 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
130 printf("Deleted "); 129 printf("Deleted ");
131 130
132 printf("%d: %s", ifi->ifi_index, 131 printf("%d: %s", ifi->ifi_index,
133 tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>"); 132 /*tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>" - we checked tb[IFLA_IFNAME] above*/
134 133 (char*)RTA_DATA(tb[IFLA_IFNAME])
135 if (tb[IFLA_LINK]) { 134 );
136 SPRINT_BUF(b1); 135
137 int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); 136 {
138 if (iflink == 0) 137 unsigned m_flag = 0;
139 printf("@NONE: "); 138 if (tb[IFLA_LINK]) {
140 else { 139 SPRINT_BUF(b1);
141 printf("@%s: ", ll_idx_n2a(iflink, b1)); 140 int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
142 m_flag = ll_index_to_flags(iflink); 141 if (iflink == 0)
143 m_flag = !(m_flag & IFF_UP); 142 printf("@NONE: ");
143 else {
144 printf("@%s: ", ll_idx_n2a(iflink, b1));
145 m_flag = ll_index_to_flags(iflink);
146 m_flag = !(m_flag & IFF_UP);
147 }
148 } else {
149 printf(": ");
144 } 150 }
145 } else { 151 print_link_flags(ifi->ifi_flags, m_flag);
146 printf(": ");
147 } 152 }
148 print_link_flags(ifi->ifi_flags, m_flag);
149 153
150 if (tb[IFLA_MTU]) 154 if (tb[IFLA_MTU])
151 printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU])); 155 printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
@@ -382,12 +386,10 @@ static int FAST_FUNC store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr
382 struct nlmsg_list *h; 386 struct nlmsg_list *h;
383 struct nlmsg_list **lp; 387 struct nlmsg_list **lp;
384 388
385 h = malloc(n->nlmsg_len+sizeof(void*)); 389 h = xzalloc(n->nlmsg_len + sizeof(void*));
386 if (h == NULL)
387 return -1;
388 390
389 memcpy(&h->h, n, n->nlmsg_len); 391 memcpy(&h->h, n, n->nlmsg_len);
390 h->next = NULL; 392 /*h->next = NULL; - xzalloc did it */
391 393
392 for (lp = linfo; *lp; lp = &(*lp)->next) 394 for (lp = linfo; *lp; lp = &(*lp)->next)
393 continue; 395 continue;