2009-07-16 Pavel Roskin <proski@gnu.org>

* kern/mm.c (grub_zalloc): New function.
	(grub_debug_zalloc): Likewise.
	* include/grub/mm.h: Declare grub_zalloc() and
	grub_debug_zalloc().
	* util/misc.c (grub_zalloc): New function.
	* bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_zalloc()
	instead of grub_malloc(), remove unneeded initializations.
	* bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
	* commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
	* commands/parttool.c (grub_cmd_parttool): Likewise.
	* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
	* disk/raid5_recover.c (grub_raid5_recover): Likewise.
	* disk/raid6_recover.c (grub_raid6_recover): Likewise.
	* disk/usbms.c (grub_usbms_finddevs): Likewise.
	* efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
	* efiemu/pnvram.c (grub_efiemu_pnvram): Likewise.
	(grub_cmd_efiemu_pnvram): Likewise.
	* fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
	* fs/iso9660.c (grub_iso9660_mount): Likewise.
	(grub_iso9660_iterate_dir): Likewise.
	* fs/jfs.c (grub_jfs_opendir): Likewise.
	* fs/ntfs.c (list_file): Likewise.
	(grub_ntfs_mount): Likewise.
	* kern/disk.c (grub_disk_open): Likewise.
	* kern/dl.c (grub_dl_load_core): Likewise.
	* kern/elf.c (grub_elf_file): Likewise.
	* kern/env.c (grub_env_context_open): Likewise.
	(grub_env_set): Likewise.
	(grub_env_set_data_slot): Likewise.
	* kern/file.c (grub_file_open): Likewise.
	* kern/fs.c (grub_fs_blocklist_open): Likewise.
	* loader/i386/multiboot.c (grub_module): Likewise.
	* loader/xnu.c (grub_xnu_create_key): Likewise.
	(grub_xnu_create_value): Likewise.
	* normal/main.c (grub_normal_add_menu_entry): Likewise.
	(read_config_file): Likewise.
	* normal/menu_entry.c (make_screen): Likewise.
	* partmap/sun.c (sun_partition_map_iterate): Likewise.
	* script/sh/lexer.c (grub_script_lexer_init): Likewise.
	* script/sh/script.c (grub_script_parse): Likewise.
	* video/bitmap.c (grub_video_bitmap_create): Likewise.
	* video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
	* video/readers/png.c (grub_png_output_byte): Likewise.
	(grub_video_reader_png): Likewise.
This commit is contained in:
proski 2009-07-16 22:14:09 +00:00
parent 830afef7c2
commit eab58da22c
34 changed files with 132 additions and 132 deletions

View file

@ -1,3 +1,50 @@
2009-07-16 Pavel Roskin <proski@gnu.org>
* kern/mm.c (grub_zalloc): New function.
(grub_debug_zalloc): Likewise.
* include/grub/mm.h: Declare grub_zalloc() and
grub_debug_zalloc().
* util/misc.c (grub_zalloc): New function.
* bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_zalloc()
instead of grub_malloc(), remove unneeded initializations.
* bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
* commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
* commands/parttool.c (grub_cmd_parttool): Likewise.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
* disk/raid5_recover.c (grub_raid5_recover): Likewise.
* disk/raid6_recover.c (grub_raid6_recover): Likewise.
* disk/usbms.c (grub_usbms_finddevs): Likewise.
* efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
* efiemu/pnvram.c (grub_efiemu_pnvram): Likewise.
(grub_cmd_efiemu_pnvram): Likewise.
* fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
* fs/iso9660.c (grub_iso9660_mount): Likewise.
(grub_iso9660_iterate_dir): Likewise.
* fs/jfs.c (grub_jfs_opendir): Likewise.
* fs/ntfs.c (list_file): Likewise.
(grub_ntfs_mount): Likewise.
* kern/disk.c (grub_disk_open): Likewise.
* kern/dl.c (grub_dl_load_core): Likewise.
* kern/elf.c (grub_elf_file): Likewise.
* kern/env.c (grub_env_context_open): Likewise.
(grub_env_set): Likewise.
(grub_env_set_data_slot): Likewise.
* kern/file.c (grub_file_open): Likewise.
* kern/fs.c (grub_fs_blocklist_open): Likewise.
* loader/i386/multiboot.c (grub_module): Likewise.
* loader/xnu.c (grub_xnu_create_key): Likewise.
(grub_xnu_create_value): Likewise.
* normal/main.c (grub_normal_add_menu_entry): Likewise.
(read_config_file): Likewise.
* normal/menu_entry.c (make_screen): Likewise.
* partmap/sun.c (sun_partition_map_iterate): Likewise.
* script/sh/lexer.c (grub_script_lexer_init): Likewise.
* script/sh/script.c (grub_script_parse): Likewise.
* video/bitmap.c (grub_video_bitmap_create): Likewise.
* video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
* video/readers/png.c (grub_png_output_byte): Likewise.
(grub_video_reader_png): Likewise.
2009-07-16 Vladimir Serbinenko <phcoder@gmail.com>
Enable all targets that can be built by default

View file

@ -170,14 +170,11 @@ grub_uhci_pci_iter (int bus, int device, int func,
return 0;
/* Allocate memory for the controller and register it. */
u = grub_malloc (sizeof (*u));
u = grub_zalloc (sizeof (*u));
if (! u)
return 1;
u->iobase = base & GRUB_UHCI_IOMASK;
u->framelist = 0;
u->qh = 0;
u->td = 0;
grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
class, subclass, interf, u->iobase);

View file

@ -33,13 +33,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
grub_usb_device_t dev;
int i;
dev = grub_malloc (sizeof (struct grub_usb_device));
dev = grub_zalloc (sizeof (struct grub_usb_device));
if (! dev)
return NULL;
dev->controller = *controller;
dev->addr = 0;
dev->initialized = 0;
dev->speed = speed;
grub_usb_device_initialize (dev);

View file

@ -40,8 +40,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd,
maxargs++;
/* Set up the option state. */
state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
state = grub_zalloc (sizeof (struct grub_arg_list) * maxargs);
if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
{

View file

@ -242,8 +242,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
if (grub_strcmp (args[i], "help") == 0)
return show_help ();
parsed = (int *) grub_malloc (argc * sizeof (int));
grub_memset (parsed, 0, argc * sizeof (int));
parsed = (int *) grub_zalloc (argc * sizeof (int));
for (i = 1; i < argc; i++)
if (! parsed[i])
@ -272,9 +271,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
args[i]);
ptool = cur;
pargs = (struct grub_parttool_args *)
grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
grub_memset (pargs, 0,
ptool->nargs * sizeof (struct grub_parttool_args));
grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args));
for (j = i; j < argc; j++)
if (! parsed[j])
{

View file

@ -109,12 +109,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
disk->id = drive;
data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
data = (struct grub_biosdisk_data *) grub_zalloc (sizeof (*data));
if (! data)
return grub_errno;
data->drive = drive;
data->flags = 0;
if ((cd_drive) && (drive == cd_drive))
{

View file

@ -32,12 +32,10 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
int i;
size <<= GRUB_DISK_SECTOR_BITS;
buf2 = grub_malloc (size);
buf2 = grub_zalloc (size);
if (!buf2)
return grub_errno;
grub_memset (buf, 0, size);
for (i = 0; i < (int) array->total_devs; i++)
{
grub_err_t err;

View file

@ -96,11 +96,11 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
char *pbuf = 0, *qbuf = 0;
size <<= GRUB_DISK_SECTOR_BITS;
pbuf = grub_malloc (size);
pbuf = grub_zalloc (size);
if (!pbuf)
goto quit;
qbuf = grub_malloc (size);
qbuf = grub_zalloc (size);
if (!qbuf)
goto quit;
@ -108,9 +108,6 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
if (q == (int) array->total_devs)
q = 0;
grub_memset (pbuf, 0, size);
grub_memset (qbuf, 0, size);
pos = q + 1;
if (pos == (int) array->total_devs)
pos = 0;

View file

@ -107,14 +107,12 @@ grub_usbms_finddevs (void)
}
devcnt++;
usbms = grub_malloc (sizeof (struct grub_usbms_dev));
usbms = grub_zalloc (sizeof (struct grub_usbms_dev));
if (! usbms)
return 1;
usbms->dev = usbdev;
usbms->interface = i;
usbms->in = NULL;
usbms->out = NULL;
/* Iterate over all endpoints of this interface, at least a
IN and OUT bulk endpoint are required. */

View file

@ -104,14 +104,12 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
requested_memory[type] += align_overhead + size;
/* Remember the request */
ret = grub_malloc (sizeof (*ret));
ret = grub_zalloc (sizeof (*ret));
if (!ret)
return -1;
ret->type = type;
ret->size = size;
ret->align_overhead = align_overhead;
ret->val = 0;
ret->next = 0;
prev = 0;
/* Add request to the end of the chain.

View file

@ -339,11 +339,10 @@ grub_efiemu_pnvram (void)
accuracy = 50000000;
daylight = 0;
nvram = grub_malloc (nvramsize);
nvram = grub_zalloc (nvramsize);
if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage");
grub_memset (nvram, 0, nvramsize);
return grub_efiemu_make_nvram ();
}
@ -365,11 +364,10 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
nvram = grub_malloc (nvramsize);
nvram = grub_zalloc (nvramsize);
if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage");
grub_memset (nvram, 0, nvramsize);
if (argc == 1 && (err = read_pnvram (args[0])))
{

View file

@ -146,11 +146,10 @@ grub_pxefs_open (struct grub_file *file, const char *name)
if (c.c2.status)
return grub_error (GRUB_ERR_BAD_FS, "open fails");
data = grub_malloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
data = grub_zalloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
if (! data)
return grub_errno;
data->packet_number = 0;
data->block_size = grub_pxe_blksize;
grub_strcpy (data->filename, name);

View file

@ -263,13 +263,11 @@ grub_iso9660_mount (grub_disk_t disk)
return 0;
}
data = grub_malloc (sizeof (struct grub_iso9660_data));
data = grub_zalloc (sizeof (struct grub_iso9660_data));
if (! data)
return 0;
data->disk = disk;
data->rockridge = 0;
data->joliet = 0;
block = 16;
do
@ -509,8 +507,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
else
{
size = entry->len - 5;
filename = grub_malloc (size + 1);
filename[0] = '\0';
filename = grub_zalloc (size + 1);
}
filename_alloc = 1;
grub_strncpy (filename, (char *) &entry->data[1], size);

View file

@ -382,11 +382,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
return 0;
}
diro = grub_malloc (sizeof (struct grub_jfs_diropen));
diro = grub_zalloc (sizeof (struct grub_jfs_diropen));
if (!diro)
return 0;
diro->index = 0;
diro->data = data;
diro->inode = inode;
@ -397,7 +396,6 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
diro->sorted = (char *) (inode->dir.header.sorted);
diro->count = inode->dir.header.count;
diro->dirpage = 0;
return diro;
}

View file

@ -601,11 +601,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,
(u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
GRUB_FSHELP_REG;
fdiro = grub_malloc (sizeof (struct grub_ntfs_file));
fdiro = grub_zalloc (sizeof (struct grub_ntfs_file));
if (!fdiro)
return 0;
grub_memset (fdiro, 0, sizeof (*fdiro));
fdiro->data = diro->data;
fdiro->ino = u32at (pos, 0);
@ -791,12 +790,10 @@ grub_ntfs_mount (grub_disk_t disk)
if (!disk)
goto fail;
data = (struct grub_ntfs_data *) grub_malloc (sizeof (*data));
data = (struct grub_ntfs_data *) grub_zalloc (sizeof (*data));
if (!data)
goto fail;
grub_memset (data, 0, sizeof (*data));
data->disk = disk;
/* Read the BPB. */

View file

@ -30,6 +30,7 @@
void grub_mm_init_region (void *addr, grub_size_t size);
void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
void *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
void EXPORT_FUNC(grub_free) (void *ptr);
void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
@ -45,6 +46,9 @@ void grub_mm_dump (unsigned lineno);
#define grub_malloc(size) \
grub_debug_malloc (__FILE__, __LINE__, size)
#define grub_zalloc(size) \
grub_debug_zalloc (__FILE__, __LINE__, size)
#define grub_realloc(ptr,size) \
grub_debug_realloc (__FILE__, __LINE__, ptr, size)
@ -56,6 +60,8 @@ void grub_mm_dump (unsigned lineno);
void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
grub_size_t size);
void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line,
grub_size_t size);
void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
grub_size_t size);

View file

@ -244,14 +244,10 @@ grub_disk_open (const char *name)
grub_dprintf ("disk", "Opening `%s'...\n", name);
disk = (grub_disk_t) grub_malloc (sizeof (*disk));
disk = (grub_disk_t) grub_zalloc (sizeof (*disk));
if (! disk)
return 0;
disk->dev = 0;
disk->read_hook = 0;
disk->partition = 0;
disk->data = 0;
disk->name = grub_strdup (name);
if (! disk->name)
goto fail;

View file

@ -535,16 +535,11 @@ grub_dl_load_core (void *addr, grub_size_t size)
return 0;
}
mod = (grub_dl_t) grub_malloc (sizeof (*mod));
mod = (grub_dl_t) grub_zalloc (sizeof (*mod));
if (! mod)
return 0;
mod->name = 0;
mod->ref_count = 1;
mod->dep = 0;
mod->segment = 0;
mod->init = 0;
mod->fini = 0;
grub_dprintf ("modules", "relocating to %p\n", mod);
if (grub_dl_resolve_name (mod, e)

View file

@ -61,12 +61,11 @@ grub_elf_file (grub_file_t file)
{
grub_elf_t elf;
elf = grub_malloc (sizeof (*elf));
elf = grub_zalloc (sizeof (*elf));
if (! elf)
return 0;
elf->file = file;
elf->phdrs = 0;
if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
goto fail;

View file

@ -80,11 +80,10 @@ grub_env_context_open (int export)
struct grub_env_context *context;
int i;
context = grub_malloc (sizeof (*context));
context = grub_zalloc (sizeof (*context));
if (! context)
return grub_errno;
grub_memset (context, 0, sizeof (*context));
context->prev = current_context;
current_context = context;
@ -204,12 +203,10 @@ grub_env_set (const char *name, const char *val)
}
/* The variable does not exist, so create a new one. */
var = grub_malloc (sizeof (*var));
var = grub_zalloc (sizeof (*var));
if (! var)
return grub_errno;
grub_memset (var, 0, sizeof (*var));
/* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave
this for readability. */
var->type = GRUB_ENV_VAR_LOCAL;
@ -379,12 +376,10 @@ grub_env_set_data_slot (const char *name, const void *ptr)
}
/* The variable does not exist, so create a new one. */
var = grub_malloc (sizeof (*var));
var = grub_zalloc (sizeof (*var));
if (! var)
goto fail;
grub_memset (var, 0, sizeof (*var));
var->type = GRUB_ENV_VAR_DATA;
var->name = mangled_name;
var->value = (char *) ptr;

View file

@ -75,14 +75,11 @@ grub_file_open (const char *name)
if (! device)
goto fail;
file = (grub_file_t) grub_malloc (sizeof (*file));
file = (grub_file_t) grub_zalloc (sizeof (*file));
if (! file)
goto fail;
file->device = device;
file->offset = 0;
file->data = 0;
file->read_hook = 0;
if (device->disk && file_name[0] != '/')
/* This is a block list. */

View file

@ -161,7 +161,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
while (p);
/* Allocate a block list. */
blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1));
if (! blocks)
return 0;
@ -179,8 +179,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
goto fail;
}
}
else
blocks[i].offset = 0;
p++;
blocks[i].length = grub_strtoul (p, &p, 0);
@ -203,7 +201,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
p++;
}
blocks[i].length = 0;
file->data = blocks;
return GRUB_ERR_NONE;

View file

@ -68,6 +68,7 @@
#ifdef MM_DEBUG
# undef grub_malloc
# undef grub_zalloc
# undef grub_realloc
# undef grub_free
# undef grub_memalign
@ -348,6 +349,19 @@ grub_malloc (grub_size_t size)
return grub_memalign (0, size);
}
/* Allocate SIZE bytes, clear them and return the pointer. */
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = grub_memalign (0, size);
if (ret)
grub_memset (ret, 0, size);
return ret;
}
/* Deallocate the pointer PTR. */
void
grub_free (void *ptr)
@ -522,6 +536,19 @@ grub_debug_malloc (const char *file, int line, grub_size_t size)
return ptr;
}
void *
grub_debug_zalloc (const char *file, int line, grub_size_t size)
{
void *ptr;
if (grub_mm_debug)
grub_printf ("%s:%d: zalloc (0x%zx) = ", file, line, size);
ptr = grub_zalloc (size);
if (grub_mm_debug)
grub_printf ("%p\n", ptr);
return ptr;
}
void
grub_debug_free (const char *file, int line, void *ptr)
{

View file

@ -456,13 +456,12 @@ grub_module (int argc, char *argv[])
}
else
{
struct grub_mod_list *modlist = grub_malloc (sizeof (struct grub_mod_list));
struct grub_mod_list *modlist = grub_zalloc (sizeof (struct grub_mod_list));
if (! modlist)
goto fail;
modlist->mod_start = (grub_uint32_t) module;
modlist->mod_end = (grub_uint32_t) module + size;
modlist->cmdline = (grub_uint32_t) cmdline;
modlist->pad = 0;
mbi->mods_count = 1;
mbi->mods_addr = (grub_uint32_t) modlist;
mbi->flags |= MULTIBOOT_INFO_MODS;

View file

@ -278,7 +278,7 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
ret = grub_xnu_find_key (*parent, name);
if (ret)
return ret;
ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
if (! ret)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
@ -292,7 +292,6 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
return 0;
}
ret->datasize = -1;
ret->first_child = 0;
ret->next = *parent;
*parent = ret;
return ret;
@ -313,7 +312,7 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
ret->data = 0;
return ret;
}
ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
if (! ret)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
@ -326,8 +325,6 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
return 0;
}
ret->datasize = 0;
ret->data = 0;
ret->next = *parent;
*parent = ret;
return ret;

View file

@ -166,11 +166,9 @@ grub_normal_add_menu_entry (int argc, const char **args,
struct grub_menu_entry_class *classes_tail;
/* Allocate dummy head node for class list. */
classes_head = grub_malloc (sizeof (struct grub_menu_entry_class));
classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
if (! classes_head)
return grub_errno;
classes_head->name = 0;
classes_head->next = 0;
classes_tail = classes_head;
menu = grub_env_get_data_slot ("menu");
@ -206,7 +204,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
}
/* Create a new class and add it at the tail of the list. */
new_class = grub_malloc (sizeof (struct grub_menu_entry_class));
new_class = grub_zalloc (sizeof (struct grub_menu_entry_class));
if (! new_class)
{
grub_free (class_name);
@ -215,7 +213,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
}
/* Fill in the new class node. */
new_class->name = class_name;
new_class->next = 0;
/* Link the tail to it, and make it the new tail. */
classes_tail->next = new_class;
classes_tail = new_class;
@ -267,7 +264,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
while (*last)
last = &(*last)->next;
*last = grub_malloc (sizeof (**last));
*last = grub_zalloc (sizeof (**last));
if (! *last)
{
free_menu_entry_classes (classes_head);
@ -278,7 +275,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
(*last)->title = menutitle;
(*last)->classes = classes_head;
(*last)->next = 0;
(*last)->sourcecode = menusourcecode;
menu->size++;
@ -346,11 +342,9 @@ read_config_file (const char *config)
newmenu = grub_env_get_data_slot ("menu");
if (! newmenu)
{
newmenu = grub_malloc (sizeof (*newmenu));
newmenu = grub_zalloc (sizeof (*newmenu));
if (! newmenu)
return 0;
newmenu->size = 0;
newmenu->entry_list = 0;
grub_env_set_data_slot ("menu", newmenu);
}

View file

@ -416,18 +416,11 @@ make_screen (grub_menu_entry_t entry)
struct screen *screen;
/* Initialize the screen. */
screen = grub_malloc (sizeof (*screen));
screen = grub_zalloc (sizeof (*screen));
if (! screen)
return 0;
screen->num_lines = 1;
screen->column = 0;
screen->real_column = 0;
screen->line = 0;
screen->x = 0;
screen->y = 0;
screen->killed_text = 0;
screen->completion_shown = 0;
screen->lines = grub_malloc (sizeof (struct line));
if (! screen->lines)
goto fail;

View file

@ -95,12 +95,10 @@ sun_partition_map_iterate (grub_disk_t disk,
raw = *disk;
raw.partition = 0;
p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition));
p = (grub_partition_t) grub_zalloc (sizeof (struct grub_partition));
if (! p)
return grub_errno;
p->offset = 0;
p->data = 0;
p->partmap = &grub_sun_partition_map;
if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
&block) == GRUB_ERR_NONE)

View file

@ -49,22 +49,13 @@ grub_script_lexer_init (char *script, grub_reader_getline_t getline)
{
struct grub_lexer_param *param;
param = grub_malloc (sizeof (*param));
param = grub_zalloc (sizeof (*param));
if (! param)
return 0;
param->state = GRUB_PARSER_STATE_TEXT;
param->getline = getline;
param->refs = 0;
param->done = 0;
param->newscript = 0;
param->script = script;
param->record = 0;
param->recording = 0;
param->recordpos = 0;
param->recordlen = 0;
param->tokenonhold = 0;
param->was_newline = 0;
return param;
}

View file

@ -304,15 +304,10 @@ grub_script_parse (char *script, grub_reader_getline_t getline)
if (! parsed)
return 0;
parsestate = grub_malloc (sizeof (*parsestate));
parsestate = grub_zalloc (sizeof (*parsestate));
if (! parsestate)
return 0;
parsestate->err = 0;
parsestate->func_mem = 0;
parsestate->memused = 0;
parsestate->parsed = 0;
/* Initialize the lexer. */
lexstate = grub_script_lexer_init (script, getline);
if (! lexstate)

View file

@ -257,6 +257,16 @@ grub_malloc (grub_size_t size)
return xmalloc (size);
}
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = xmalloc (size);
memset (ret, 0, size);
return ret;
}
void
grub_free (void *ptr)
{

View file

@ -137,7 +137,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
/* Calculate size needed for the data. */
size = (width * mode_info->bytes_per_pixel) * height;
(*bitmap)->data = grub_malloc (size);
(*bitmap)->data = grub_zalloc (size);
if (! (*bitmap)->data)
{
grub_free (*bitmap);
@ -146,9 +146,6 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
return grub_errno;
}
/* Clear bitmap. */
grub_memset ((*bitmap)->data, 0, size);
return GRUB_ERR_NONE;
}

View file

@ -667,12 +667,11 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
if (!file)
return grub_errno;
data = grub_malloc (sizeof (*data));
data = grub_zalloc (sizeof (*data));
if (data != NULL)
{
int i;
grub_memset (data, 0, sizeof (*data));
data->file = file;
data->bitmap = bitmap;
grub_jpeg_decode_jpeg (data);

View file

@ -543,11 +543,10 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n)
if (data->first_line)
{
blank_line = grub_malloc (row_bytes);
blank_line = grub_zalloc (row_bytes);
if (blank_line == NULL)
return grub_errno;
grub_memset (blank_line, 0, row_bytes);
up = blank_line;
}
else
@ -843,10 +842,9 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
if (!file)
return grub_errno;
data = grub_malloc (sizeof (*data));
data = grub_zalloc (sizeof (*data));
if (data != NULL)
{
grub_memset (data, 0, sizeof (*data));
data->file = file;
data->bitmap = bitmap;