Add missing malloc failure checks

Also add errno = ENOMEM because it is said that that some malloc
implementations might miss to do so.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
Stefan Richter 2010-06-05 14:55:53 +02:00
parent b15039ceb8
commit 9d47becf25
2 changed files with 19 additions and 5 deletions

View File

@ -463,8 +463,10 @@ iso_init(fw_handle_t handle, int type,
handle->iso.packet_count = 0; handle->iso.packet_count = 0;
handle->iso.packets = handle->iso.packets =
malloc(handle->iso.irq_interval * sizeof handle->iso.packets[0]); malloc(handle->iso.irq_interval * sizeof handle->iso.packets[0]);
if (handle->iso.packets == NULL) if (handle->iso.packets == NULL) {
errno = ENOMEM;
return -1; return -1;
}
handle->iso.fd = open(handle->iso.filename, O_RDWR); handle->iso.fd = open(handle->iso.filename, O_RDWR);
if (handle->iso.fd < 0) { if (handle->iso.fd < 0) {

View File

@ -419,9 +419,13 @@ fw_handle_t fw_new_handle(void)
struct epoll_event ep; struct epoll_event ep;
int i; int i;
memset(&ep, 0, sizeof(ep));
handle = malloc(sizeof *handle); handle = malloc(sizeof *handle);
if (handle == NULL) {
errno = ENOMEM;
return NULL;
}
memset(&ep, 0, sizeof(ep));
memset(handle, 0, sizeof(*handle)); memset(handle, 0, sizeof(*handle));
handle->tag_handler = default_tag_handler; handle->tag_handler = default_tag_handler;
@ -775,6 +779,10 @@ handle_arm_request(raw1394handle_t handle, struct address_closure *ac,
return 0; return 0;
rrb = malloc(sizeof *rrb + in_length + response.length); rrb = malloc(sizeof *rrb + in_length + response.length);
if (rrb == NULL) {
errno == ENOMEM;
return -1;
}
rrb->request_response.request = &rrb->request; rrb->request_response.request = &rrb->request;
rrb->request_response.response = &rrb->response; rrb->request_response.response = &rrb->response;
@ -818,8 +826,10 @@ fw_arm_register(fw_handle_t handle, nodeaddr_t start,
int retval; int retval;
allocation = malloc(sizeof *allocation + length); allocation = malloc(sizeof *allocation + length);
if (allocation == NULL) if (allocation == NULL) {
errno = ENOMEM;
return -1; return -1;
}
allocation->closure.callback = handle_arm_request; allocation->closure.callback = handle_arm_request;
allocation->buffer = initial_value; allocation->buffer = initial_value;
@ -1318,8 +1328,10 @@ fw_start_fcp_listen(fw_handle_t handle)
struct address_closure *closure; struct address_closure *closure;
closure = malloc(sizeof *closure); closure = malloc(sizeof *closure);
if (closure == NULL) if (closure == NULL) {
errno = ENOMEM;
return -1; return -1;
}
closure->callback = handle_fcp_request; closure->callback = handle_fcp_request;