mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
Merge pull request #26115 from yuwata/test-fix-memleak-fdleak
test: fix memleak and fd leak
This commit is contained in:
commit
a6a9ee4b36
@ -53,7 +53,6 @@ static uint8_t advertisement[] = {
|
|||||||
|
|
||||||
static bool test_stopped;
|
static bool test_stopped;
|
||||||
static int test_fd[2];
|
static int test_fd[2];
|
||||||
static sd_event_source *recv_router_advertisement;
|
|
||||||
static struct {
|
static struct {
|
||||||
struct in6_addr address;
|
struct in6_addr address;
|
||||||
unsigned char prefixlen;
|
unsigned char prefixlen;
|
||||||
@ -281,9 +280,9 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ra) {
|
TEST(ra) {
|
||||||
sd_event *e;
|
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||||
sd_radv *ra;
|
_cleanup_(sd_event_source_unrefp) sd_event_source *recv_router_advertisement = NULL;
|
||||||
unsigned i;
|
_cleanup_(sd_radv_unrefp) sd_radv *ra = NULL;
|
||||||
|
|
||||||
assert_se(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0);
|
assert_se(socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0);
|
||||||
|
|
||||||
@ -303,7 +302,7 @@ TEST(ra) {
|
|||||||
assert_se(sd_radv_set_rdnss(ra, 60, &test_rdnss, 1) >= 0);
|
assert_se(sd_radv_set_rdnss(ra, 60, &test_rdnss, 1) >= 0);
|
||||||
assert_se(sd_radv_set_dnssl(ra, 60, (char **)test_dnssl) >= 0);
|
assert_se(sd_radv_set_dnssl(ra, 60, (char **)test_dnssl) >= 0);
|
||||||
|
|
||||||
for (i = 0; i < ELEMENTSOF(prefix); i++) {
|
for (unsigned i = 0; i < ELEMENTSOF(prefix); i++) {
|
||||||
sd_radv_prefix *p;
|
sd_radv_prefix *p;
|
||||||
|
|
||||||
printf("Test prefix %u\n", i);
|
printf("Test prefix %u\n", i);
|
||||||
@ -324,8 +323,8 @@ TEST(ra) {
|
|||||||
assert_se(!p);
|
assert_se(!p);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0],
|
assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0], EPOLLIN, radv_recv, ra) >= 0);
|
||||||
EPOLLIN, radv_recv, ra) >= 0);
|
assert_se(sd_event_source_set_io_fd_own(recv_router_advertisement, true) >= 0);
|
||||||
|
|
||||||
assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME,
|
assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME,
|
||||||
2 * USEC_PER_SEC, 0,
|
2 * USEC_PER_SEC, 0,
|
||||||
@ -334,13 +333,6 @@ TEST(ra) {
|
|||||||
assert_se(sd_radv_start(ra) >= 0);
|
assert_se(sd_radv_start(ra) >= 0);
|
||||||
|
|
||||||
assert_se(sd_event_loop(e) >= 0);
|
assert_se(sd_event_loop(e) >= 0);
|
||||||
|
|
||||||
ra = sd_radv_unref(ra);
|
|
||||||
assert_se(!ra);
|
|
||||||
|
|
||||||
close(test_fd[0]);
|
|
||||||
|
|
||||||
sd_event_unref(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "sd-ndisc.h"
|
#include "sd-ndisc.h"
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
|
#include "fd-util.h"
|
||||||
#include "hexdecoct.h"
|
#include "hexdecoct.h"
|
||||||
#include "icmp6-util.h"
|
#include "icmp6-util.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
@ -255,8 +256,8 @@ static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(rs) {
|
TEST(rs) {
|
||||||
sd_event *e;
|
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||||
sd_ndisc *nd;
|
_cleanup_(sd_ndisc_unrefp) sd_ndisc *nd = NULL;
|
||||||
|
|
||||||
send_ra_function = send_ra;
|
send_ra_function = send_ra;
|
||||||
|
|
||||||
@ -279,17 +280,13 @@ TEST(rs) {
|
|||||||
assert_se(sd_ndisc_start(nd) >= 0);
|
assert_se(sd_ndisc_start(nd) >= 0);
|
||||||
assert_se(sd_ndisc_start(nd) >= 0);
|
assert_se(sd_ndisc_start(nd) >= 0);
|
||||||
assert_se(sd_ndisc_stop(nd) >= 0);
|
assert_se(sd_ndisc_stop(nd) >= 0);
|
||||||
|
test_fd[1] = safe_close(test_fd[1]);
|
||||||
|
|
||||||
assert_se(sd_ndisc_start(nd) >= 0);
|
assert_se(sd_ndisc_start(nd) >= 0);
|
||||||
|
|
||||||
assert_se(sd_event_loop(e) >= 0);
|
assert_se(sd_event_loop(e) >= 0);
|
||||||
|
|
||||||
nd = sd_ndisc_unref(nd);
|
test_fd[1] = safe_close(test_fd[1]);
|
||||||
assert_se(!nd);
|
|
||||||
|
|
||||||
close(test_fd[1]);
|
|
||||||
|
|
||||||
sd_event_unref(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_timeout_value(uint8_t flags) {
|
static int test_timeout_value(uint8_t flags) {
|
||||||
@ -342,8 +339,8 @@ static int test_timeout_value(uint8_t flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(timeout) {
|
TEST(timeout) {
|
||||||
sd_event *e;
|
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||||
sd_ndisc *nd;
|
_cleanup_(sd_ndisc_unrefp) sd_ndisc *nd = NULL;
|
||||||
|
|
||||||
send_ra_function = test_timeout_value;
|
send_ra_function = test_timeout_value;
|
||||||
|
|
||||||
@ -367,9 +364,7 @@ TEST(timeout) {
|
|||||||
|
|
||||||
assert_se(sd_event_loop(e) >= 0);
|
assert_se(sd_event_loop(e) >= 0);
|
||||||
|
|
||||||
nd = sd_ndisc_unref(nd);
|
test_fd[1] = safe_close(test_fd[1]);
|
||||||
|
|
||||||
sd_event_unref(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||||
|
@ -242,11 +242,13 @@ TEST_RET(unit_printf, .sd_booted = true) {
|
|||||||
*user, *group, *uid, *gid, *home, *shell,
|
*user, *group, *uid, *gid, *home, *shell,
|
||||||
*tmp_dir, *var_tmp_dir;
|
*tmp_dir, *var_tmp_dir;
|
||||||
_cleanup_(manager_freep) Manager *m = NULL;
|
_cleanup_(manager_freep) Manager *m = NULL;
|
||||||
|
_cleanup_close_ int fd = -EBADF;
|
||||||
Unit *u;
|
Unit *u;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/test-unit_printf.XXXXXX";
|
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/test-unit_printf.XXXXXX";
|
||||||
assert_se(mkostemp_safe(filename) >= 0);
|
fd = mkostemp_safe(filename);
|
||||||
|
assert_se(fd >= 0);
|
||||||
|
|
||||||
/* Using the specifier functions is admittedly a bit circular, but we don't want to reimplement the
|
/* Using the specifier functions is admittedly a bit circular, but we don't want to reimplement the
|
||||||
* logic a second time. We're at least testing that the hookup works. */
|
* logic a second time. We're at least testing that the hookup works. */
|
||||||
|
Loading…
Reference in New Issue
Block a user