Skip to content

Commit

Permalink
lkl tools: lib: fix lkl_opendir error reporting
Browse files Browse the repository at this point in the history
The error code was not properly initialized in case of success or when
we don't have enough memory to allocate the lkl_dir structure.

Signed-off-by: Octavian Purdila <tavi@cs.pub.ro>
  • Loading branch information
tavip committed Dec 22, 2017
1 parent e495865 commit 3b08376
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,10 @@ struct lkl_dir *lkl_opendir(const char *path, int *err)
{
struct lkl_dir *dir = lkl_dir_alloc(err);

if (!dir)
if (!dir) {
*err = -LKL_ENOMEM;
return NULL;
}

dir->fd = lkl_sys_open(path, LKL_O_RDONLY | LKL_O_DIRECTORY, 0);
if (dir->fd < 0) {
Expand All @@ -345,6 +347,8 @@ struct lkl_dir *lkl_opendir(const char *path, int *err)
return NULL;
}

*err = 0;

return dir;
}

Expand Down

0 comments on commit 3b08376

Please sign in to comment.