return 1;
}
- dst = calloc(length, sizeof(char));
+ dst = zalloc(length);
if (!dst)
die("memory allocation failed - maybe length is too large?\n");
- src = calloc(length, sizeof(char));
+ src = zalloc(length);
if (!src)
die("memory allocation failed - maybe length is too large?\n");
while (*p)
p = &((*p)->next);
- *p = calloc(1, (sizeof(**p) + len + 1));
+ *p = zalloc(sizeof(**p) + len + 1);
strncpy((*p)->name, name, len);
}
size_t len,
const char *value)
{
- struct man_viewer_info_list *new = calloc(1, sizeof(*new) + len + 1);
+ struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1);
strncpy(new->name, name, len);
new->info = strdup(value);
{
char *buf;
int i, len, ret;
- pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
+ pp->probes[0] = buf = zalloc(MAX_CMDLEN);
if (!buf)
- die("Failed to allocate memory by calloc.");
+ die("Failed to allocate memory by zalloc.");
ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
if (ret <= 0 || ret >= MAX_CMDLEN)
goto error;
static struct sched_atom *
get_new_event(struct task_desc *task, u64 timestamp)
{
- struct sched_atom *event = calloc(1, sizeof(*event));
+ struct sched_atom *event = zalloc(sizeof(*event));
unsigned long idx = task->nr_events;
size_t size;
return;
}
- wakee_event->wait_sem = calloc(1, sizeof(*wakee_event->wait_sem));
+ wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem));
sem_init(wakee_event->wait_sem, 0, 0);
wakee_event->specific_wait = 1;
event->wait_sem = wakee_event->wait_sem;
if (task)
return task;
- task = calloc(1, sizeof(*task));
+ task = zalloc(sizeof(*task));
task->pid = pid;
task->nr = nr_tasks;
strcpy(task->comm, comm);
static void thread_atoms_insert(struct thread *thread)
{
- struct work_atoms *atoms;
-
- atoms = calloc(sizeof(*atoms), 1);
+ struct work_atoms *atoms = zalloc(sizeof(*atoms));
if (!atoms)
die("No memory");
char run_state,
u64 timestamp)
{
- struct work_atom *atom;
-
- atom = calloc(sizeof(*atom), 1);
+ struct work_atom *atom = zalloc(sizeof(*atom));
if (!atom)
die("Non memory");
return;
if (syme->src == NULL) {
- syme->src = calloc(1, sizeof(*source));
+ syme->src = zalloc(sizeof(*source));
if (syme->src == NULL)
return;
pthread_mutex_init(&syme->src->lock, NULL);
*/
struct perf_header *perf_header__new(void)
{
- struct perf_header *self = calloc(sizeof(*self), 1);
+ struct perf_header *self = zalloc(sizeof(*self));
if (self != NULL) {
self->size = 1;
if (id == config) {
closedir(evt_dir);
closedir(sys_dir);
- path = calloc(1, sizeof(path));
+ path = zalloc(sizeof(path));
path->system = malloc(MAX_EVENT_LENGTH);
if (!path->system) {
free(path);
static struct symbol *symbol__new(u64 start, u64 len, const char *name)
{
size_t namelen = strlen(name) + 1;
- struct symbol *self = calloc(1, (symbol__priv_size +
- sizeof(*self) + namelen));
- if (!self)
+ struct symbol *self = zalloc(symbol__priv_size +
+ sizeof(*self) + namelen);
+ if (self == NULL)
return NULL;
- if (symbol__priv_size) {
- memset(self, 0, symbol__priv_size);
+ if (symbol__priv_size)
self = ((void *)self) + symbol__priv_size;
- }
+
self->start = start;
self->end = len ? start + len - 1 : start;
static struct thread *thread__new(pid_t pid)
{
- struct thread *self = calloc(1, sizeof(*self));
+ struct thread *self = zalloc(sizeof(*self));
if (self != NULL) {
self->pid = pid;
extern FILE *xfdopen(int fd, const char *mode);
extern int xmkstemp(char *template);
+static inline void *zalloc(size_t size)
+{
+ return calloc(1, size);
+}
+
static inline size_t xsize_t(off_t len)
{
return (size_t)len;