From 6e081a0c57f0f6f14428f7cb78bb22f6848fe4af Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 28 Sep 2011 04:45:30 -0500 Subject: Move pacsave path construction code off the stack This is definitely not in the normal hot path, so we can afford to do some temporary heap allocation here. Signed-off-by: Dan McGee --- lib/libalpm/remove.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/libalpm/remove.c') diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index e998763f..a3aa4a53 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -317,17 +317,21 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info, int cmp = filehash ? strcmp(filehash, backup->hash) : 0; FREE(filehash); if(cmp != 0) { - char newpath[PATH_MAX]; - snprintf(newpath, PATH_MAX, "%s.pacsave", file); + char *newpath; + size_t len = strlen(file) + 8 + 1; + MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); + snprintf(newpath, len, "%s.pacsave", file); if(rename(file, newpath)) { _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"), file, newpath, strerror(errno)); alpm_logaction(handle, "error: could not rename %s to %s (%s)\n", file, newpath, strerror(errno)); + free(newpath); return -1; } _alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); alpm_logaction(handle, "warning: %s saved as %s\n", file, newpath); + free(newpath); return 0; } } -- cgit v1.2.3-24-g4f1b