*: fix places where we were still using malloc/realloc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
ef3817c6dc
commit
9037787eae
@ -50,9 +50,7 @@ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
|
|||||||
/* Use "memcpy" for pointer assignments here to avoid problems
|
/* Use "memcpy" for pointer assignments here to avoid problems
|
||||||
* with C99 strict type aliasing rules. */
|
* with C99 strict type aliasing rules. */
|
||||||
memcpy(&p, ptr, sizeof (p));
|
memcpy(&p, ptr, sizeof (p));
|
||||||
p = realloc(p, size);
|
p = xrealloc(p, size);
|
||||||
if (!p)
|
|
||||||
return EXT2_ET_NO_MEMORY;
|
|
||||||
memcpy(ptr, &p, sizeof (p));
|
memcpy(ptr, &p, sizeof (p));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -377,8 +377,7 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
|
|||||||
{
|
{
|
||||||
struct fs_info *fs;
|
struct fs_info *fs;
|
||||||
|
|
||||||
if (!(fs = malloc(sizeof(struct fs_info))))
|
fs = xmalloc(sizeof(struct fs_info));
|
||||||
return NULL;
|
|
||||||
|
|
||||||
fs->device = string_copy(device);
|
fs->device = string_copy(device);
|
||||||
fs->mountpt = string_copy(mntpnt);
|
fs->mountpt = string_copy(mntpnt);
|
||||||
@ -573,10 +572,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
|
|||||||
struct fsck_instance *inst, *p;
|
struct fsck_instance *inst, *p;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
inst = malloc(sizeof(struct fsck_instance));
|
inst = xzalloc(sizeof(struct fsck_instance));
|
||||||
if (!inst)
|
|
||||||
return ENOMEM;
|
|
||||||
memset(inst, 0, sizeof(struct fsck_instance));
|
|
||||||
|
|
||||||
prog = xasprintf("fsck.%s", type);
|
prog = xasprintf("fsck.%s", type);
|
||||||
argv[0] = prog;
|
argv[0] = prog;
|
||||||
|
19
editors/ed.c
19
editors/ed.c
@ -454,11 +454,7 @@ static void subCommand(const char *cmd, int num1, int num2)
|
|||||||
* structure and use that. Link it in in place of
|
* structure and use that. Link it in in place of
|
||||||
* the old line structure.
|
* the old line structure.
|
||||||
*/
|
*/
|
||||||
nlp = malloc(sizeof(LINE) + lp->len + deltaLen);
|
nlp = xmalloc(sizeof(LINE) + lp->len + deltaLen);
|
||||||
if (nlp == NULL) {
|
|
||||||
bb_error_msg("can't get memory for line");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlp->len = lp->len + deltaLen;
|
nlp->len = lp->len + deltaLen;
|
||||||
|
|
||||||
@ -712,12 +708,7 @@ static int readLines(const char *file, int num)
|
|||||||
|
|
||||||
if (bufUsed >= bufSize) {
|
if (bufUsed >= bufSize) {
|
||||||
len = (bufSize * 3) / 2;
|
len = (bufSize * 3) / 2;
|
||||||
cp = realloc(bufBase, len);
|
cp = xrealloc(bufBase, len);
|
||||||
if (cp == NULL) {
|
|
||||||
bb_error_msg("no memory for buffer");
|
|
||||||
close(fd);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
bufBase = cp;
|
bufBase = cp;
|
||||||
bufPtr = bufBase + bufUsed;
|
bufPtr = bufBase + bufUsed;
|
||||||
bufSize = len;
|
bufSize = len;
|
||||||
@ -872,11 +863,7 @@ static int insertLine(int num, const char *data, int len)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
newLp = malloc(sizeof(LINE) + len - 1);
|
newLp = xmalloc(sizeof(LINE) + len - 1);
|
||||||
if (newLp == NULL) {
|
|
||||||
bb_error_msg("failed to allocate memory for line");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(newLp->data, data, len);
|
memcpy(newLp->data, data, len);
|
||||||
newLp->len = len;
|
newLp->len = len;
|
||||||
|
@ -1094,7 +1094,7 @@ static void process_files(void)
|
|||||||
/* append next_line, read new next_line. */
|
/* append next_line, read new next_line. */
|
||||||
}
|
}
|
||||||
len = strlen(pattern_space);
|
len = strlen(pattern_space);
|
||||||
pattern_space = realloc(pattern_space, len + strlen(next_line) + 2);
|
pattern_space = xrealloc(pattern_space, len + strlen(next_line) + 2);
|
||||||
pattern_space[len] = '\n';
|
pattern_space[len] = '\n';
|
||||||
strcpy(pattern_space + len+1, next_line);
|
strcpy(pattern_space + len+1, next_line);
|
||||||
last_gets_char = next_gets_char;
|
last_gets_char = next_gets_char;
|
||||||
|
@ -99,7 +99,6 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
|
|||||||
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
||||||
struct rtattr *tb[IFLA_MAX+1];
|
struct rtattr *tb[IFLA_MAX+1];
|
||||||
int len = n->nlmsg_len;
|
int len = n->nlmsg_len;
|
||||||
unsigned m_flag = 0;
|
|
||||||
|
|
||||||
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
|
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
|
||||||
return 0;
|
return 0;
|
||||||
@ -130,8 +129,12 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
|
|||||||
printf("Deleted ");
|
printf("Deleted ");
|
||||||
|
|
||||||
printf("%d: %s", ifi->ifi_index,
|
printf("%d: %s", ifi->ifi_index,
|
||||||
tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>");
|
/*tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>" - we checked tb[IFLA_IFNAME] above*/
|
||||||
|
(char*)RTA_DATA(tb[IFLA_IFNAME])
|
||||||
|
);
|
||||||
|
|
||||||
|
{
|
||||||
|
unsigned m_flag = 0;
|
||||||
if (tb[IFLA_LINK]) {
|
if (tb[IFLA_LINK]) {
|
||||||
SPRINT_BUF(b1);
|
SPRINT_BUF(b1);
|
||||||
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
|
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
|
||||||
@ -146,6 +149,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
|
|||||||
printf(": ");
|
printf(": ");
|
||||||
}
|
}
|
||||||
print_link_flags(ifi->ifi_flags, m_flag);
|
print_link_flags(ifi->ifi_flags, m_flag);
|
||||||
|
}
|
||||||
|
|
||||||
if (tb[IFLA_MTU])
|
if (tb[IFLA_MTU])
|
||||||
printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
|
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
|
|||||||
struct nlmsg_list *h;
|
struct nlmsg_list *h;
|
||||||
struct nlmsg_list **lp;
|
struct nlmsg_list **lp;
|
||||||
|
|
||||||
h = malloc(n->nlmsg_len+sizeof(void*));
|
h = xzalloc(n->nlmsg_len + sizeof(void*));
|
||||||
if (h == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
memcpy(&h->h, n, n->nlmsg_len);
|
memcpy(&h->h, n, n->nlmsg_len);
|
||||||
h->next = NULL;
|
/*h->next = NULL; - xzalloc did it */
|
||||||
|
|
||||||
for (lp = linfo; *lp; lp = &(*lp)->next)
|
for (lp = linfo; *lp; lp = &(*lp)->next)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user