mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 15:00:05 +01:00
util: fix a memleak in mkdir_p
In the error case path would leak. Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
This commit is contained in:
parent
051ac26a20
commit
6770131e94
2 changed files with 22 additions and 3 deletions
|
|
@ -43,14 +43,14 @@ mkdir_p(const char *dir)
|
|||
|
||||
path = safe_strdup(dir);
|
||||
parent = dirname(path);
|
||||
rc = mkdir_p(parent);
|
||||
free(path);
|
||||
|
||||
if ((rc = mkdir_p(parent)) < 0)
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
rc = mkdir(dir, 0755);
|
||||
|
||||
free(path);
|
||||
|
||||
return (rc == -1 && errno != EEXIST) ? -errno : 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@
|
|||
|
||||
#include <valgrind/valgrind.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "litest.h"
|
||||
#include "litest-runner.h"
|
||||
#include "util-files.h"
|
||||
#include "util-list.h"
|
||||
#include "util-strings.h"
|
||||
#include "util-time.h"
|
||||
|
|
@ -48,6 +50,21 @@
|
|||
#define TEST_VERSIONSORT
|
||||
#include "libinput-versionsort.h"
|
||||
|
||||
START_TEST(mkdir_p_test)
|
||||
{
|
||||
const char *testdir = "/tmp/litest_mkdir_test";
|
||||
litest_assert_neg_errno_success(mkdir_p("/"));
|
||||
|
||||
unlink(testdir);
|
||||
litest_assert_neg_errno_success(mkdir_p(testdir));
|
||||
/* EEXIST is not an error */
|
||||
litest_assert_neg_errno_success(mkdir_p(testdir));
|
||||
unlink(testdir);
|
||||
|
||||
litest_assert_int_eq(mkdir_p("/proc/foo"), -ENOENT);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(array_for_each)
|
||||
{
|
||||
int ai[6];
|
||||
|
|
@ -2048,6 +2065,8 @@ int main(void)
|
|||
litest_runner_add_test(runner, &tdesc); \
|
||||
} while(0)
|
||||
|
||||
ADD_TEST(mkdir_p_test);
|
||||
|
||||
ADD_TEST(array_for_each);
|
||||
|
||||
ADD_TEST(bitfield_helpers);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue