fixed a file descriptor leak
This commit is contained in:
parent
2ab57b6022
commit
04424f5e89
2 changed files with 20 additions and 5 deletions
|
@ -447,17 +447,20 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
|
||||||
if(nb) {
|
if(nb) {
|
||||||
char *temp;
|
char *temp;
|
||||||
char *md5_local, *md5_pkg;
|
char *md5_local, *md5_pkg;
|
||||||
|
int fd;
|
||||||
|
|
||||||
md5_local = MDFile(expath);
|
|
||||||
/* extract the package's version to a temporary file and md5 it */
|
/* extract the package's version to a temporary file and md5 it */
|
||||||
temp = strdup("/tmp/alpm_XXXXXX");
|
temp = strdup("/tmp/alpm_XXXXXX");
|
||||||
mkstemp(temp);
|
fd = mkstemp(temp);
|
||||||
if(tar_extract_file(tar, temp)) {
|
if(tar_extract_file(tar, temp)) {
|
||||||
alpm_logaction("could not extract %s (%s)", pathname, strerror(errno));
|
alpm_logaction("could not extract %s (%s)", pathname, strerror(errno));
|
||||||
errors++;
|
errors++;
|
||||||
FREE(md5_local);
|
unlink(temp);
|
||||||
|
FREE(temp);
|
||||||
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
md5_local = MDFile(expath);
|
||||||
md5_pkg = MDFile(temp);
|
md5_pkg = MDFile(temp);
|
||||||
/* append the new md5 hash to it's respective entry in info->backup
|
/* append the new md5 hash to it's respective entry in info->backup
|
||||||
* (it will be the new orginal)
|
* (it will be the new orginal)
|
||||||
|
@ -550,6 +553,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
|
||||||
FREE(md5_orig);
|
FREE(md5_orig);
|
||||||
unlink(temp);
|
unlink(temp);
|
||||||
FREE(temp);
|
FREE(temp);
|
||||||
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
if(!notouch) {
|
if(!notouch) {
|
||||||
_alpm_log(PM_LOG_FLOW2, "extracting %s", pathname);
|
_alpm_log(PM_LOG_FLOW2, "extracting %s", pathname);
|
||||||
|
|
|
@ -279,32 +279,41 @@ pmpkg_t *pkg_load(char *pkgfile)
|
||||||
}
|
}
|
||||||
if(!strcmp(th_get_pathname(tar), ".PKGINFO")) {
|
if(!strcmp(th_get_pathname(tar), ".PKGINFO")) {
|
||||||
char *descfile;
|
char *descfile;
|
||||||
|
int fd;
|
||||||
|
|
||||||
/* extract this file into /tmp. it has info for us */
|
/* extract this file into /tmp. it has info for us */
|
||||||
descfile = strdup("/tmp/alpm_XXXXXX");
|
descfile = strdup("/tmp/alpm_XXXXXX");
|
||||||
mkstemp(descfile);
|
fd = mkstemp(descfile);
|
||||||
tar_extract_file(tar, descfile);
|
tar_extract_file(tar, descfile);
|
||||||
/* parse the info file */
|
/* parse the info file */
|
||||||
if(parse_descfile(descfile, info, 0) == -1) {
|
if(parse_descfile(descfile, info, 0) == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, "could not parse the package description file");
|
_alpm_log(PM_LOG_ERROR, "could not parse the package description file");
|
||||||
pm_errno = PM_ERR_PKG_INVALID;
|
pm_errno = PM_ERR_PKG_INVALID;
|
||||||
|
unlink(descfile);
|
||||||
FREE(descfile);
|
FREE(descfile);
|
||||||
|
close(fd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(!strlen(info->name)) {
|
if(!strlen(info->name)) {
|
||||||
_alpm_log(PM_LOG_ERROR, "missing package name in %s", pkgfile);
|
_alpm_log(PM_LOG_ERROR, "missing package name in %s", pkgfile);
|
||||||
pm_errno = PM_ERR_PKG_INVALID;
|
pm_errno = PM_ERR_PKG_INVALID;
|
||||||
|
unlink(descfile);
|
||||||
FREE(descfile);
|
FREE(descfile);
|
||||||
|
close(fd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if(!strlen(info->version)) {
|
if(!strlen(info->version)) {
|
||||||
_alpm_log(PM_LOG_ERROR, "missing package version in %s", pkgfile);
|
_alpm_log(PM_LOG_ERROR, "missing package version in %s", pkgfile);
|
||||||
pm_errno = PM_ERR_PKG_INVALID;
|
pm_errno = PM_ERR_PKG_INVALID;
|
||||||
|
unlink(descfile);
|
||||||
FREE(descfile);
|
FREE(descfile);
|
||||||
|
close(fd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
config = 1;
|
config = 1;
|
||||||
|
unlink(descfile);
|
||||||
FREE(descfile);
|
FREE(descfile);
|
||||||
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
} else if(!strcmp(th_get_pathname(tar), "._install") || !strcmp(th_get_pathname(tar), ".INSTALL")) {
|
} else if(!strcmp(th_get_pathname(tar), "._install") || !strcmp(th_get_pathname(tar), ".INSTALL")) {
|
||||||
info->scriptlet = 1;
|
info->scriptlet = 1;
|
||||||
|
@ -314,10 +323,11 @@ pmpkg_t *pkg_load(char *pkgfile)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *fn;
|
char *fn;
|
||||||
char *str;
|
char *str;
|
||||||
|
int fd;
|
||||||
|
|
||||||
MALLOC(str, PATH_MAX);
|
MALLOC(str, PATH_MAX);
|
||||||
fn = strdup("/tmp/alpm_XXXXXX");
|
fn = strdup("/tmp/alpm_XXXXXX");
|
||||||
mkstemp(fn);
|
fd = mkstemp(fn);
|
||||||
tar_extract_file(tar, fn);
|
tar_extract_file(tar, fn);
|
||||||
fp = fopen(fn, "r");
|
fp = fopen(fn, "r");
|
||||||
while(!feof(fp)) {
|
while(!feof(fp)) {
|
||||||
|
@ -333,6 +343,7 @@ pmpkg_t *pkg_load(char *pkgfile)
|
||||||
_alpm_log(PM_LOG_WARNING, "could not remove tempfile %s", fn);
|
_alpm_log(PM_LOG_WARNING, "could not remove tempfile %s", fn);
|
||||||
}
|
}
|
||||||
FREE(fn);
|
FREE(fn);
|
||||||
|
close(fd);
|
||||||
filelist = 1;
|
filelist = 1;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue