summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-11-01 13:55:10 -0500
committerAllan McRae <allan@archlinux.org>2015-11-04 15:05:52 +1000
commit978b197120f3a942cad36726e9678fbbabe3e660 (patch)
tree2e4407bee8483522df185ab330b2a522dec2688f /src/pacman
parent0d877ec4296fdde75946301f9a44723f7cbce5bd (diff)
files: do not unnecessarily strdup targets
Targets are never modified so we can just use the original copy. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/files.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 27bcf4fd..3bb2f2ba 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -54,19 +54,13 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
alpm_list_t *t;
for(t = targets; t; t = alpm_list_next(t)) {
- char *filename = NULL, *f;
+ char *filename = t->data;
int found = 0;
alpm_list_t *s;
- size_t len;
+ size_t len = strlen(filename);
- if((filename = strdup(t->data)) == NULL) {
- goto notfound;
- }
-
- len = strlen(filename);
- f = filename;
- while(len > 1 && f[0] == '/') {
- f = f + 1;
+ while(len > 1 && filename[0] == '/') {
+ filename++;
len--;
}
@@ -79,11 +73,11 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
alpm_pkg_t *pkg = p->data;
alpm_filelist_t *files = alpm_pkg_get_files(pkg);
- if(alpm_filelist_contains(files, f)) {
+ if(alpm_filelist_contains(files, filename)) {
if(config->op_f_machinereadable) {
- print_line_machinereadable(repo, pkg, f);
+ print_line_machinereadable(repo, pkg, filename);
} else if(!config->quiet) {
- printf(_("%s is owned by %s/%s %s\n"), f,
+ printf(_("%s is owned by %s/%s %s\n"), filename,
alpm_db_get_name(repo), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
} else {
@@ -95,9 +89,6 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
}
}
- free(filename);
-
-notfound:
if(!found) {
ret++;
}
@@ -112,19 +103,14 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
const colstr_t *colstr = &config->colstr;
for(t = targets; t; t = alpm_list_next(t)) {
- char *targ = NULL;
+ char *targ = t->data;
alpm_list_t *s;
int found = 0;
regex_t reg;
- if((targ = strdup(t->data)) == NULL) {
- goto notfound;
- }
-
if(regex) {
if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
/* TODO: error message */
- free(targ);
goto notfound;
}
}
@@ -151,7 +137,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
m = strcmp(c + 1, targ);
}
if(m == 0) {
- match = alpm_list_add(match, strdup(files->files[f].name));
+ match = alpm_list_add(match, files->files[f].name);
found = 1;
}
}
@@ -178,12 +164,11 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
printf(" %s\n", c);
}
}
- FREELIST(match);
+ alpm_list_free(match);
}
}
}
- free(targ);
notfound:
if(!found) {