mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-07 11:58:02 -05:00
Use MALLOC throughtout libalpm
Use MALLOC instead of malloc for safety in libalpm. Some changes are pure refactoring, but for others this provides a success check for memory allocation. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
f3a280bc67
commit
ffdc2c5396
@ -743,11 +743,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
|||||||
/* since we know the length of the file string already,
|
/* since we know the length of the file string already,
|
||||||
* we can do malloc + memcpy rather than strdup */
|
* we can do malloc + memcpy rather than strdup */
|
||||||
len += 1;
|
len += 1;
|
||||||
files[files_count].name = malloc(len);
|
MALLOC(files[files_count].name, len, goto error);
|
||||||
if(files[files_count].name == NULL) {
|
|
||||||
_alpm_alloc_fail(len);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
memcpy(files[files_count].name, line, len);
|
memcpy(files[files_count].name, line, len);
|
||||||
files_count++;
|
files_count++;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
#include "filelist.h"
|
#include "filelist.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct package_changelog {
|
struct package_changelog {
|
||||||
struct archive *archive;
|
struct archive *archive;
|
||||||
@ -404,11 +405,8 @@ static int add_entry_to_files_list(alpm_pkg_t *pkg, size_t *files_size,
|
|||||||
* Other code relies on it to detect directories so add it here.*/
|
* Other code relies on it to detect directories so add it here.*/
|
||||||
if(type == AE_IFDIR && path[pathlen - 1] != '/') {
|
if(type == AE_IFDIR && path[pathlen - 1] != '/') {
|
||||||
/* 2 = 1 for / + 1 for \0 */
|
/* 2 = 1 for / + 1 for \0 */
|
||||||
char *newpath = malloc(pathlen + 2);
|
char *newpath;
|
||||||
if (!newpath) {
|
MALLOC(newpath, pathlen + 2, return -1);
|
||||||
_alpm_alloc_fail(pathlen + 2);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strcpy(newpath, path);
|
strcpy(newpath, path);
|
||||||
newpath[pathlen] = '/';
|
newpath[pathlen] = '/';
|
||||||
newpath[pathlen + 1] = '\0';
|
newpath[pathlen + 1] = '\0';
|
||||||
|
@ -172,10 +172,7 @@ static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg,
|
|||||||
|
|
||||||
position = get_hash_position(pkg->name_hash, hash);
|
position = get_hash_position(pkg->name_hash, hash);
|
||||||
|
|
||||||
ptr = malloc(sizeof(alpm_list_t));
|
MALLOC(ptr, sizeof(alpm_list_t), return hash);
|
||||||
if(ptr == NULL) {
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr->data = pkg;
|
ptr->data = pkg;
|
||||||
ptr->prev = ptr;
|
ptr->prev = ptr;
|
||||||
|
@ -1135,8 +1135,9 @@ static int check_validity(alpm_handle_t *handle,
|
|||||||
|
|
||||||
if(_alpm_pkg_validate_internal(handle, v.path, v.pkg,
|
if(_alpm_pkg_validate_internal(handle, v.path, v.pkg,
|
||||||
v.level, &v.siglist, &v.validation) == -1) {
|
v.level, &v.siglist, &v.validation) == -1) {
|
||||||
|
struct validity *invalid;
|
||||||
v.error = handle->pm_errno;
|
v.error = handle->pm_errno;
|
||||||
struct validity *invalid = malloc(sizeof(struct validity));
|
MALLOC(invalid, sizeof(struct validity), return -1);
|
||||||
memcpy(invalid, &v, sizeof(struct validity));
|
memcpy(invalid, &v, sizeof(struct validity));
|
||||||
errors = alpm_list_add(errors, invalid);
|
errors = alpm_list_add(errors, invalid);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user