mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-15 22:05:02 -05:00
Memory allocation and other small cleanups
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
4bd0a85095
commit
ee2bbb39b5
@ -422,7 +422,7 @@ static int extract_single_file(struct archive *archive,
|
|||||||
|
|
||||||
/* if we force hash_orig to be non-NULL retroactive backup works */
|
/* if we force hash_orig to be non-NULL retroactive backup works */
|
||||||
if(needbackup && !hash_orig) {
|
if(needbackup && !hash_orig) {
|
||||||
hash_orig = strdup("");
|
STRDUP(hash_orig, "", RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,12 +434,16 @@ static int extract_single_file(struct archive *archive,
|
|||||||
char *tempfile;
|
char *tempfile;
|
||||||
char *hash_local = NULL, *hash_pkg = NULL;
|
char *hash_local = NULL, *hash_pkg = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* extract the package's version to a temporary file and checksum it */
|
/* extract the package's version to a temporary file and checksum it */
|
||||||
tempfile = strdup("/tmp/alpm_XXXXXX");
|
STRDUP(tempfile, "/tmp/alpm_XXXXXX", RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
fd = mkstemp(tempfile);
|
fd = mkstemp(tempfile);
|
||||||
|
if(fd == -1) {
|
||||||
|
RET_ERR(PM_ERR_SYSTEM, -1);
|
||||||
|
}
|
||||||
|
|
||||||
int ret = archive_read_data_into_fd(archive, fd);
|
ret = archive_read_data_into_fd(archive, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
if(ret == ARCHIVE_WARN) {
|
if(ret == ARCHIVE_WARN) {
|
||||||
/* operation succeeded but a non-critical error was encountered */
|
/* operation succeeded but a non-critical error was encountered */
|
||||||
@ -471,10 +475,7 @@ static int extract_single_file(struct archive *archive,
|
|||||||
char *backup = NULL;
|
char *backup = NULL;
|
||||||
/* length is tab char, null byte and MD5 (32 char) */
|
/* length is tab char, null byte and MD5 (32 char) */
|
||||||
int backup_len = strlen(oldbackup) + 34;
|
int backup_len = strlen(oldbackup) + 34;
|
||||||
backup = malloc(backup_len);
|
MALLOC(backup, backup_len, RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
if(!backup) {
|
|
||||||
RET_ERR(PM_ERR_MEMORY, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(backup, "%s\t%s", oldbackup, hash_pkg);
|
sprintf(backup, "%s\t%s", oldbackup, hash_pkg);
|
||||||
backup[backup_len-1] = '\0';
|
backup[backup_len-1] = '\0';
|
||||||
@ -610,10 +611,7 @@ static int extract_single_file(struct archive *archive,
|
|||||||
_alpm_log(PM_LOG_DEBUG, "appending backup entry for %s\n", filename);
|
_alpm_log(PM_LOG_DEBUG, "appending backup entry for %s\n", filename);
|
||||||
|
|
||||||
hash = alpm_get_md5sum(filename);
|
hash = alpm_get_md5sum(filename);
|
||||||
backup = malloc(backup_len);
|
MALLOC(backup, backup_len, RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
if(!backup) {
|
|
||||||
RET_ERR(PM_ERR_MEMORY, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(backup, "%s\t%s", oldbackup, hash);
|
sprintf(backup, "%s\t%s", oldbackup, hash);
|
||||||
backup[backup_len-1] = '\0';
|
backup[backup_len-1] = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user