xbps-repo: index.c: oldpkgver might be undefined if entry is removed from index.

This commit is contained in:
Juan RP 2012-01-17 11:25:45 +01:00
parent 9906aa7029
commit 4fdf675249

View File

@ -161,7 +161,7 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
prop_array_t pkgar; prop_array_t pkgar;
struct stat st; struct stat st;
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver; const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
char *sha256, *filen, *tmpfilen, *oldfilepath; char *sha256, *filen, *tmpfilen, *oldfilepath, *buf;
int rv = 0; int rv = 0;
if (idxdict == NULL || file == NULL) if (idxdict == NULL || file == NULL)
@ -216,19 +216,27 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
"filename", &oldfilen); "filename", &oldfilen);
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &oldpkgver); "pkgver", &oldpkgver);
buf = strdup(oldpkgver);
if (buf == NULL) {
prop_object_release(newpkgd);
rv = ENOMEM;
goto out;
}
oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen); oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen);
if (oldfilepath == NULL) { if (oldfilepath == NULL) {
prop_object_release(newpkgd);
rv = errno; rv = errno;
prop_object_release(newpkgd);
free(buf);
goto out; goto out;
} }
if (remove(oldfilepath) == -1) { if (remove(oldfilepath) == -1) {
rv = errno;
xbps_error_printf("failed to remove old " xbps_error_printf("failed to remove old "
"package file `%s': %s\n", oldfilepath, "package file `%s': %s\n", oldfilepath,
strerror(errno)); strerror(errno));
free(oldfilepath); free(oldfilepath);
prop_object_release(newpkgd); prop_object_release(newpkgd);
rv = errno; free(buf);
goto out; goto out;
} }
free(oldfilepath); free(oldfilepath);
@ -237,10 +245,12 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
xbps_error_printf("failed to remove `%s' " xbps_error_printf("failed to remove `%s' "
"from plist index: %s\n", pkgname, strerror(errno)); "from plist index: %s\n", pkgname, strerror(errno));
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(buf);
goto out; goto out;
} }
printf("Removed obsole package entry/binpkg for `%s'.\n", printf("Removed obsolete package entry/binpkg for `%s'.\n",
oldpkgver); buf);
free(buf);
} }
/* /*