1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

alpm_list: use malloc instead of calloc

In every case we were calling calloc, the struct we allocated (or the
memory to be used) is fully specified later in the method.

For alpm_list_t allocations, we always set all of data, next, and prev.

For list copying and transforming to an array, we always copy the entire
data element, so no need to zero it first.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-27 16:14:17 -05:00
parent 619c3629ca
commit bf56fb6eb8
2 changed files with 8 additions and 8 deletions

View File

@ -89,7 +89,7 @@ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
{
alpm_list_t *ptr, *lp;
ptr = calloc(1, sizeof(alpm_list_t));
ptr = malloc(sizeof(alpm_list_t));
if(ptr == NULL) {
return list;
}
@ -127,7 +127,7 @@ alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_
} else {
alpm_list_t *add = NULL, *prev = NULL, *next = list;
add = calloc(1, sizeof(alpm_list_t));
add = malloc(sizeof(alpm_list_t));
if(add == NULL) {
return list;
}
@ -470,7 +470,7 @@ alpm_list_t SYMEXPORT *alpm_list_copy_data(const alpm_list_t *list,
const alpm_list_t *lp = list;
alpm_list_t *newlist = NULL;
while(lp) {
void *newdata = calloc(1, size);
void *newdata = malloc(size);
if(newdata) {
memcpy(newdata, lp->data, size);
newlist = alpm_list_add(newlist, newdata);
@ -775,7 +775,7 @@ void SYMEXPORT *alpm_list_to_array(const alpm_list_t *list, size_t n,
return NULL;
}
array = calloc(n, size);
array = malloc(n * size);
if(array == NULL) {
return NULL;
}

View File

@ -159,14 +159,14 @@ static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg, in
position = get_hash_position(pkg->name_hash, hash);
ptr = calloc(1, sizeof(alpm_list_t));
ptr = malloc(sizeof(alpm_list_t));
if(ptr == NULL) {
return hash;
}
ptr->data = pkg;
ptr->next = NULL;
ptr->prev = ptr;
ptr->next = NULL;
hash->hash_table[position] = ptr;
if(!sorted) {