Changed all malloc() to calloc()

This commit is contained in:
Thomas Schmitt 2010-07-12 19:37:31 +00:00
parent 15266fb310
commit 2a48b34bcd
13 changed files with 29 additions and 34 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2010.07.12.193201" #define Cdrskin_timestamP "2010.07.12.193644"

View File

@ -143,7 +143,7 @@ static void add_worker(int w_type, struct burn_drive *d,
pthread_attr_t attr; pthread_attr_t attr;
#endif #endif
a = malloc(sizeof(struct w_list)); a = calloc(1, sizeof(struct w_list));
a->w_type = w_type; a->w_type = w_type;
a->drive = d; a->drive = d;
a->u = *(union w_list_data *)data; a->u = *(union w_list_data *)data;

View File

@ -12,9 +12,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
/* #include <m alloc.h> ts A61013 : not in GNU/Linux man 3 malloc */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
@ -1297,7 +1294,7 @@ int burn_drive_add_whitelist(char *device_address)
if(enumeration_whitelist_top+1 >= BURN_DRIVE_WHITELIST_LEN) if(enumeration_whitelist_top+1 >= BURN_DRIVE_WHITELIST_LEN)
return 0; return 0;
enumeration_whitelist_top++; enumeration_whitelist_top++;
new_item = malloc(strlen(device_address) + 1); new_item = calloc(1, strlen(device_address) + 1);
if (new_item == NULL) if (new_item == NULL)
return -1; return -1;
strcpy(new_item, device_address); strcpy(new_item, device_address);
@ -2221,7 +2218,7 @@ int burn_speed_descriptor_new(struct burn_speed_descriptor **s,
{ {
struct burn_speed_descriptor *o; struct burn_speed_descriptor *o;
(*s) = o = malloc(sizeof(struct burn_speed_descriptor)); (*s) = o = calloc(1, sizeof(struct burn_speed_descriptor));
if (o == NULL) if (o == NULL)
return -1; return -1;
o->source = 0; o->source = 0;
@ -2392,7 +2389,7 @@ int burn_disc_get_multi_caps(struct burn_drive *d, enum burn_write_types wt,
if(s == BURN_DISC_UNGRABBED) if(s == BURN_DISC_UNGRABBED)
return -1; return -1;
*caps = o = (struct burn_multi_caps *) *caps = o = (struct burn_multi_caps *)
malloc(sizeof(struct burn_multi_caps)); calloc(1, sizeof(struct burn_multi_caps));
if(*caps == NULL) if(*caps == NULL)
return -1; return -1;
/* Default says nothing is available */ /* Default says nothing is available */

View File

@ -129,7 +129,7 @@ struct burn_source *burn_file_source_new(const char *path, const char *subpath)
return NULL; return NULL;
} }
} }
fs = malloc(sizeof(struct burn_source_file)); fs = calloc(1, sizeof(struct burn_source_file));
/* ts A70825 */ /* ts A70825 */
if (fs == NULL) { if (fs == NULL) {
@ -175,7 +175,7 @@ struct burn_source *burn_fd_source_new(int datafd, int subfd, off_t size)
if (datafd == -1) if (datafd == -1)
return NULL; return NULL;
fs = malloc(sizeof(struct burn_source_file)); fs = calloc(1, sizeof(struct burn_source_file));
if (fs == NULL) /* ts A70825 */ if (fs == NULL) /* ts A70825 */
return NULL; return NULL;
fs->datafd = datafd; fs->datafd = datafd;
@ -508,7 +508,7 @@ struct burn_source *burn_fifo_source_new(struct burn_source *inp,
"Desired fifo buffer too small", 0, 0); "Desired fifo buffer too small", 0, 0);
return NULL; return NULL;
} }
fs = malloc(sizeof(struct burn_source_fifo)); fs = calloc(1, sizeof(struct burn_source_fifo));
if (fs == NULL) if (fs == NULL)
return NULL; return NULL;
fs->is_started = 0; fs->is_started = 0;

View File

@ -35,7 +35,7 @@ int libdax_audioxtr_new(struct libdax_audioxtr **xtr, char *path, int flag)
int ret= -1; int ret= -1;
struct libdax_audioxtr *o; struct libdax_audioxtr *o;
o= *xtr= (struct libdax_audioxtr *) malloc(sizeof(struct libdax_audioxtr)); o= *xtr= (struct libdax_audioxtr *) calloc(1, sizeof(struct libdax_audioxtr));
if(o==NULL) if(o==NULL)
return(-1); return(-1);
strncpy(o->path,path,LIBDAX_AUDIOXTR_STRLEN-1); strncpy(o->path,path,LIBDAX_AUDIOXTR_STRLEN-1);

View File

@ -37,7 +37,7 @@ static int libdax_msgs_item_new(struct libdax_msgs_item **item,
struct timezone tz; struct timezone tz;
(*item)= o= (*item)= o=
(struct libdax_msgs_item *) malloc(sizeof(struct libdax_msgs_item)); (struct libdax_msgs_item *) calloc(1, sizeof(struct libdax_msgs_item));
if(o==NULL) if(o==NULL)
return(-1); return(-1);
o->timestamp= 0.0; o->timestamp= 0.0;
@ -140,7 +140,7 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag)
{ {
struct libdax_msgs *o; struct libdax_msgs *o;
(*m)= o= (struct libdax_msgs *) malloc(sizeof(struct libdax_msgs)); (*m)= o= (struct libdax_msgs *) calloc(1, sizeof(struct libdax_msgs));
if(o==NULL) if(o==NULL)
return(-1); return(-1);
o->refcount= 1; o->refcount= 1;
@ -370,7 +370,7 @@ int libdax_msgs_submit(struct libdax_msgs *m, int origin, int error_code,
item->severity= severity; item->severity= severity;
item->priority= priority; item->priority= priority;
if(msg_text!=NULL) { if(msg_text!=NULL) {
item->msg_text= malloc(strlen(msg_text)+1); item->msg_text= calloc(1, strlen(msg_text)+1);
if(item->msg_text==NULL) if(item->msg_text==NULL)
goto failed; goto failed;
strcpy(item->msg_text,msg_text); strcpy(item->msg_text,msg_text);

View File

@ -1165,7 +1165,7 @@ int mmc_fake_toc(struct burn_drive *d)
if (d->disc == NULL) if (d->disc == NULL)
return -1; return -1;
d->toc_entries = d->last_track_no + d->complete_sessions; d->toc_entries = d->last_track_no + d->complete_sessions;
d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry)); d->toc_entry = calloc(d->toc_entries, sizeof(struct burn_toc_entry));
if (d->toc_entry == NULL) if (d->toc_entry == NULL)
return -1; return -1;
memset(d->toc_entry, 0,d->toc_entries * sizeof(struct burn_toc_entry)); memset(d->toc_entry, 0,d->toc_entries * sizeof(struct burn_toc_entry));

View File

@ -24,7 +24,7 @@ struct burn_source *burn_null_source_new(void)
{ {
struct burn_source *src; struct burn_source *src;
src = malloc(sizeof(struct burn_source)); src = calloc(1, sizeof(struct burn_source));
src->refcount = 1; src->refcount = 1;
src->read = null_read; src->read = null_read;
src->read_sub = NULL; src->read_sub = NULL;

View File

@ -27,7 +27,7 @@ struct burn_write_opts *burn_write_opts_new(struct burn_drive *drive)
{ {
struct burn_write_opts *opts; struct burn_write_opts *opts;
opts = malloc(sizeof(struct burn_write_opts)); opts = calloc(1, sizeof(struct burn_write_opts));
if (opts == NULL) { if (opts == NULL) {
libdax_msgs_submit(libdax_messenger, -1, 0x00020111, libdax_msgs_submit(libdax_messenger, -1, 0x00020111,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
@ -68,7 +68,7 @@ struct burn_read_opts *burn_read_opts_new(struct burn_drive *drive)
{ {
struct burn_read_opts *opts; struct burn_read_opts *opts;
opts = malloc(sizeof(struct burn_read_opts)); opts = calloc(1, sizeof(struct burn_read_opts));
opts->drive = drive; opts->drive = drive;
opts->refcount = 1; opts->refcount = 1;
opts->raw = 0; opts->raw = 0;
@ -125,7 +125,7 @@ void burn_write_opts_set_toc_entries(struct burn_write_opts *opts, int count,
struct burn_toc_entry *toc_entries) struct burn_toc_entry *toc_entries)
{ {
opts->toc_entries = count; opts->toc_entries = count;
opts->toc_entry = malloc(count * sizeof(struct burn_toc_entry)); opts->toc_entry = calloc(count, sizeof(struct burn_toc_entry));
memcpy(opts->toc_entry, &toc_entries, memcpy(opts->toc_entry, &toc_entries,
sizeof(struct burn_toc_entry) * count); sizeof(struct burn_toc_entry) * count);
} }

View File

@ -9,9 +9,6 @@
#include "../config.h" #include "../config.h"
#endif #endif
/* #include <m alloc.h> ts A61013 : not in GNU/Linux man 3 malloc */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>

View File

@ -169,9 +169,10 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx)
idx->ccb.ccb_h.func_code = XPT_DEV_MATCH; idx->ccb.ccb_h.func_code = XPT_DEV_MATCH;
idx->bufsize = sizeof(struct dev_match_result) * 100; idx->bufsize = sizeof(struct dev_match_result) * 100;
idx->ccb.cdm.match_buf_len = idx->bufsize; idx->ccb.cdm.match_buf_len = idx->bufsize;
idx->ccb.cdm.matches = (struct dev_match_result *)malloc(idx->bufsize); idx->ccb.cdm.matches = (struct dev_match_result *)
calloc(1, idx->bufsize);
if (idx->ccb.cdm.matches == NULL) { if (idx->ccb.cdm.matches == NULL) {
warnx("can't malloc memory for matches"); warnx("cannot allocate memory for matches");
close(idx->fd); close(idx->fd);
return -1; return -1;
} }

View File

@ -160,15 +160,15 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx_)
struct burn_drive_enumeration_state *idx; struct burn_drive_enumeration_state *idx;
int bufsize; int bufsize;
idx = malloc(sizeof(*idx)); idx = calloc(1, sizeof(*idx));
if (idx == NULL) { if (idx == NULL) {
warnx("can't malloc memory for enumerator"); warnx("cannot allocate memory for enumerator");
return -1; return -1;
} }
idx->skip_device = 0; idx->skip_device = 0;
if ((idx->fd = open(XPT_DEVICE, O_RDWR)) == -1) { if ((idx->fd = open(XPT_DEVICE, O_RDWR)) == -1) {
warn("couldn't open %s", XPT_DEVICE); warn("could not open %s", XPT_DEVICE);
free(idx); free(idx);
idx = NULL; idx = NULL;
return -1; return -1;
@ -183,9 +183,9 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx_)
idx->ccb.ccb_h.func_code = XPT_DEV_MATCH; idx->ccb.ccb_h.func_code = XPT_DEV_MATCH;
bufsize = sizeof(struct dev_match_result) * 100; bufsize = sizeof(struct dev_match_result) * 100;
idx->ccb.cdm.match_buf_len = bufsize; idx->ccb.cdm.match_buf_len = bufsize;
idx->ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize); idx->ccb.cdm.matches = (struct dev_match_result *) calloc(1, bufsize);
if (idx->ccb.cdm.matches == NULL) { if (idx->ccb.cdm.matches == NULL) {
warnx("can't malloc memory for matches"); warnx("cannot allocate memory for matches");
close(idx->fd); close(idx->fd);
free(idx); free(idx);
return -1; return -1;
@ -487,9 +487,9 @@ static void enumerate_common(char *fname, int bus_no, int host_no,
out.close_session = mmc_close_session; out.close_session = mmc_close_session;
out.close_track_session = mmc_close; out.close_track_session = mmc_close;
out.read_buffer_capacity = mmc_read_buffer_capacity; out.read_buffer_capacity = mmc_read_buffer_capacity;
out.idata = malloc(sizeof(struct burn_scsi_inquiry_data)); out.idata = calloc(1, sizeof(struct burn_scsi_inquiry_data));
out.idata->valid = 0; out.idata->valid = 0;
out.mdata = malloc(sizeof(struct scsi_mode_data)); out.mdata = calloc(1, sizeof(struct scsi_mode_data));
out.mdata->valid = 0; out.mdata->valid = 0;
if (out.idata == NULL || out.mdata == NULL) { if (out.idata == NULL || out.mdata == NULL) {
libdax_msgs_submit(libdax_messenger, -1, 0x00020108, libdax_msgs_submit(libdax_messenger, -1, 0x00020108,

View File

@ -34,7 +34,7 @@ char *burn_strdup(char *s)
return NULL; return NULL;
l = strlen(s) + 1; l = strlen(s) + 1;
ret = malloc(l); ret = calloc(1, l);
memcpy(ret, s, l); memcpy(ret, s, l);
return ret; return ret;
@ -52,7 +52,7 @@ char *burn_strndup(char *s, int n)
return NULL; return NULL;
l = strlen(s); l = strlen(s);
ret = malloc(l < n ? l : n); ret = calloc(1, l < n ? l : n);
memcpy(ret, s, l < n - 1 ? l : n - 1); memcpy(ret, s, l < n - 1 ? l : n - 1);
ret[n - 1] = '\0'; ret[n - 1] = '\0';