net: fix memory leaks

Found by: Coverity scan.
CID: 96638, 96648
This commit is contained in:
Andrei Borzenkov 2016-01-16 20:48:33 +03:00
parent eefa3239c2
commit 9b4256bf05

View file

@ -299,12 +299,6 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card,
char *ptr; char *ptr;
grub_net_network_level_address_t addr; grub_net_network_level_address_t addr;
name = grub_malloc (grub_strlen (card->name)
+ GRUB_NET_MAX_STR_HWADDR_LEN
+ sizeof (":link"));
if (!name)
return NULL;
addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
addr.ipv6[0] = grub_cpu_to_be64_compile_time (0xfe80ULL << 48); addr.ipv6[0] = grub_cpu_to_be64_compile_time (0xfe80ULL << 48);
addr.ipv6[1] = grub_net_ipv6_get_id (hwaddr); addr.ipv6[1] = grub_net_ipv6_get_id (hwaddr);
@ -317,6 +311,12 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card,
return inf; return inf;
} }
name = grub_malloc (grub_strlen (card->name)
+ GRUB_NET_MAX_STR_HWADDR_LEN
+ sizeof (":link"));
if (!name)
return NULL;
ptr = grub_stpcpy (name, card->name); ptr = grub_stpcpy (name, card->name);
if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0) if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0)
{ {
@ -1421,7 +1421,10 @@ grub_net_fs_open (struct grub_file *file_out, const char *name)
file->device->net->packs.last = NULL; file->device->net->packs.last = NULL;
file->device->net->name = grub_strdup (name); file->device->net->name = grub_strdup (name);
if (!file->device->net->name) if (!file->device->net->name)
return grub_errno; {
grub_free (file);
return grub_errno;
}
err = file->device->net->protocol->open (file, name); err = file->device->net->protocol->open (file, name);
if (err) if (err)