Move short-lived realpath buffers to the stack

There is little reason here to grab 4K from the heap only to return it a
few lines later. Instead, just use the stack to hold the returned value
saving ourselves the malloc/free cycle.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2012-04-29 20:14:10 -05:00
parent e0afd81d18
commit 52a9a5240a
2 changed files with 2 additions and 6 deletions

View file

@ -547,7 +547,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
* consideration cannot itself be a link, as it might be unowned- path * consideration cannot itself be a link, as it might be unowned- path
* components can be safely checked as all directories are "unowned". */ * components can be safely checked as all directories are "unowned". */
if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) { if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) {
char *rpath = calloc(PATH_MAX, sizeof(char)); char rpath[PATH_MAX];
if(realpath(path, rpath)) { if(realpath(path, rpath)) {
const char *relative_rpath = rpath + rootlen; const char *relative_rpath = rpath + rootlen;
if(_alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) { if(_alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) {
@ -556,7 +556,6 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
resolved_conflict = 1; resolved_conflict = 1;
} }
} }
free(rpath);
} }
/* is the file unowned and in the backup list of the new package? */ /* is the file unowned and in the backup list of the new package? */

View file

@ -333,7 +333,7 @@ alpm_errno_t _alpm_set_directory_option(const char *value,
char **storage, int must_exist) char **storage, int must_exist)
{ {
struct stat st; struct stat st;
char *real = NULL; char real[PATH_MAX];
const char *path; const char *path;
path = value; path = value;
@ -344,9 +344,7 @@ alpm_errno_t _alpm_set_directory_option(const char *value,
if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
return ALPM_ERR_NOT_A_DIR; return ALPM_ERR_NOT_A_DIR;
} }
CALLOC(real, PATH_MAX, sizeof(char), return ALPM_ERR_MEMORY);
if(!realpath(path, real)) { if(!realpath(path, real)) {
free(real);
return ALPM_ERR_NOT_A_DIR; return ALPM_ERR_NOT_A_DIR;
} }
path = real; path = real;
@ -359,7 +357,6 @@ alpm_errno_t _alpm_set_directory_option(const char *value,
if(!*storage) { if(!*storage) {
return ALPM_ERR_MEMORY; return ALPM_ERR_MEMORY;
} }
free(real);
return 0; return 0;
} }