aboutsummaryrefslogtreecommitdiff
path: root/libkmod
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@profusion.mobi>2011-12-09 15:33:37 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2011-12-09 15:45:55 -0200
commit4272d087800dea1754d15762ae022ead05cc35ed (patch)
tree0d2d67f3c974997c8edc0f7f4fdba5822a2a6423 /libkmod
parent33bb69b94329646748d6d362c39387ddaad6b7d6 (diff)
downloadkmod-4272d087800dea1754d15762ae022ead05cc35ed.tar.gz
Do not allocate path for known places an close resource asap
This place is not supposed to exceed PATH_MAX. So, use snprintf instead of asprintf. Close the index before iterating the values.
Diffstat (limited to 'libkmod')
-rw-r--r--libkmod/libkmod.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 975b4b4..f91e74f 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -358,23 +358,23 @@ static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx,
const char *name,
struct kmod_list **list)
{
- char *fn;
+ char fn[PATH_MAX];
int err, nmatch = 0;
struct index_file *idx;
struct index_value *realnames, *realname;
- if (asprintf(&fn, "%s/%s.bin", ctx->dirname, file) < 0)
- return -ENOMEM;
+ fn[PATH_MAX - 1] = '\0';
+ snprintf(fn, sizeof(fn) - 1, "%s/%s.bin", ctx->dirname, file);
DBG(ctx, "file=%s name=%s\n", fn, name);
idx = index_file_open(fn);
- if (idx == NULL) {
- free(fn);
+ if (idx == NULL)
return -ENOSYS;
- }
realnames = index_searchwild(idx, name);
+ index_file_close(idx);
+
for (realname = realnames; realname; realname = realnames->next) {
struct kmod_module *mod;
@@ -389,8 +389,6 @@ static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx,
}
index_values_free(realnames);
- index_file_close(idx);
- free(fn);
return nmatch;