summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-28 04:45:30 -0500
committerDan McGee <dan@archlinux.org>2011-09-28 04:48:53 -0500
commit6e081a0c57f0f6f14428f7cb78bb22f6848fe4af (patch)
treec49ef45187793d8127a52633fd9c56b2e10bc841 /lib/libalpm
parent98e0371ae38d748fb04cec4759addb54e3a618ea (diff)
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 <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/remove.c8
1 files changed, 6 insertions, 2 deletions
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;
}
}