Use calloc to request cleared memory instead.
Kernel and libc conspire to make this more efficient.
Also, replace one malloc() + strcpy() with strdup().
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
if (debug)
fprintf(stderr, "Found word %s\n", word);
him = malloc(sizeof (struct _mate));
- him->name = malloc(strlen(word) + 1);
- strcpy(him->name, word);
+ him->name = strdup(word);
him->state = STATE_OLD;
udev_list_node_append(&him->node, &bunch);
word = NULL;
{
struct volume_id *id;
- id = malloc(sizeof(struct volume_id));
+ id = calloc(1, sizeof(struct volume_id));
if (id == NULL)
return NULL;
- memset(id, 0x00, sizeof(struct volume_id));
id->fd = fd;
{
struct udev_ctrl *uctrl;
- uctrl = malloc(sizeof(struct udev_ctrl));
+ uctrl = calloc(1, sizeof(struct udev_ctrl));
if (uctrl == NULL)
return NULL;
- memset(uctrl, 0x00, sizeof(struct udev_ctrl));
uctrl->refcount = 1;
uctrl->udev = udev;
struct ucred *cred;
char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
- uctrl_msg = malloc(sizeof(struct udev_ctrl_msg));
+ uctrl_msg = calloc(1, sizeof(struct udev_ctrl_msg));
if (uctrl_msg == NULL)
return NULL;
- memset(uctrl_msg, 0x00, sizeof(struct udev_ctrl_msg));
uctrl_msg->refcount = 1;
uctrl_msg->uctrl = uctrl;
if (udev == NULL)
return NULL;
- udev_device = malloc(sizeof(struct udev_device));
+ udev_device = calloc(1, sizeof(struct udev_device));
if (udev_device == NULL)
return NULL;
- memset(udev_device, 0x00, sizeof(struct udev_device));
udev_device->refcount = 1;
udev_device->udev = udev;
udev_list_init(&udev_device->devlinks_list);
{
struct udev_enumerate *udev_enumerate;
- udev_enumerate = malloc(sizeof(struct udev_enumerate));
+ udev_enumerate = calloc(1, sizeof(struct udev_enumerate));
if (udev_enumerate == NULL)
return NULL;
- memset(udev_enumerate, 0x00, (sizeof(struct udev_enumerate)));
udev_enumerate->refcount = 1;
udev_enumerate->udev = udev;
udev_list_init(&udev_enumerate->devices_list);
return NULL;
if (socket_path == NULL)
return NULL;
- udev_monitor = malloc(sizeof(struct udev_monitor));
+ udev_monitor = calloc(1, sizeof(struct udev_monitor));
if (udev_monitor == NULL)
return NULL;
- memset(udev_monitor, 0x00, sizeof(struct udev_monitor));
udev_monitor->refcount = 1;
udev_monitor->udev = udev;
if (udev == NULL)
return NULL;
- udev_monitor = malloc(sizeof(struct udev_monitor));
+ udev_monitor = calloc(1, sizeof(struct udev_monitor));
if (udev_monitor == NULL)
return NULL;
- memset(udev_monitor, 0x00, sizeof(struct udev_monitor));
udev_monitor->refcount = 1;
udev_monitor->udev = udev;
if (udev == NULL)
return NULL;
- udev_queue = malloc(sizeof(struct udev_queue));
+ udev_queue = calloc(1, sizeof(struct udev_queue));
if (udev_queue == NULL)
return NULL;
- memset(udev_queue, 0x00, sizeof(struct udev_queue));
udev_queue->refcount = 1;
udev_queue->udev = udev;
udev_list_init(&udev_queue->queue_list);
char *config_file;
FILE *f;
- udev = malloc(sizeof(struct udev));
+ udev = calloc(1, sizeof(struct udev));
if (udev == NULL)
return NULL;
- memset(udev, 0x00, (sizeof(struct udev)));
udev->refcount = 1;
udev->log_fn = log_stderr;
udev->log_priority = LOG_ERR;
{
struct udev_event *event;
- event = malloc(sizeof(struct udev_event));
+ event = calloc(1, sizeof(struct udev_event));
if (event == NULL)
return NULL;
- memset(event, 0x00, sizeof(struct udev_event));
event->dev = dev;
event->udev = udev_device_get_udev(dev);
struct udev_list_node file_list;
struct udev_list_entry *file_loop, *file_tmp;
- rules = malloc(sizeof(struct udev_rules));
+ rules = calloc(1, sizeof(struct udev_rules));
if (rules == NULL)
return rules;
- memset(rules, 0x00, sizeof(struct udev_rules));
rules->udev = udev;
rules->resolve_names = resolve_names;
udev_list_init(&file_list);