[PATCH 1/1] tests: Add free-without-remove test
wl at ongy.net
wl at ongy.net
Fri Feb 23 08:54:56 UTC 2018
From: Markus Ongyerth <wl at ongy.net>
This is related to the discussion earlier on the mailing list and
demonstrates a problem with current wl_priv_signal_emit and wl_listener
that free themselves, but do not remove from the list.
The testcase itself passes. And I'm not sure if that can be prevented.
To reliably observe the "Invalid write of size 8" in valgrind (memcheck)
simply run `valgrind ./.libs/remove-without-free`.
Signed-of-by: Markus Ongyerth <wl at ongy.net>
---
Makefile.am | 3 ++
tests/free-without-remove.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
create mode 100644 tests/free-without-remove.c
diff --git a/Makefile.am b/Makefile.am
index 322d6b8..c51f328 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -158,6 +158,7 @@ pkgconfig_DATA += egl/wayland-egl-backend.pc
built_test_programs = \
array-test \
+ free-without-remove-test \
client-test \
display-test \
connection-test \
@@ -223,6 +224,8 @@ libtest_runner_la_LIBADD = \
array_test_SOURCES = tests/array-test.c
array_test_LDADD = libtest-runner.la
+free_without_remove_test_SOURCES = tests/free-without-remove.c
+free_without_remove_test_LDADD = libtest-runner.la
client_test_SOURCES = tests/client-test.c
client_test_LDADD = libtest-runner.la
display_test_SOURCES = tests/display-test.c
diff --git a/tests/free-without-remove.c b/tests/free-without-remove.c
new file mode 100644
index 0000000..3bc335d
--- /dev/null
+++ b/tests/free-without-remove.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright C 2018 Markus Ongyerth
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "wayland-private.h"
+#include "wayland-server.h"
+#include "test-runner.h"
+
+struct display_destroy_listener {
+ struct wl_listener listener;
+};
+
+static void
+display_destroy_notify(struct wl_listener *l, void *data)
+{
+ struct display_destroy_listener *listener =
+ container_of(l, struct display_destroy_listener, listener);
+
+ free(listener);
+}
+TEST(client_destroy_listener)
+{
+ struct wl_display *display;
+ struct display_destroy_listener *a;
+ struct display_destroy_listener *b;
+
+ a = malloc(sizeof(struct display_destroy_listener));
+ b = malloc(sizeof(struct display_destroy_listener));
+
+ display = wl_display_create();
+ a->listener.notify = display_destroy_notify;
+ b->listener.notify = display_destroy_notify;
+
+ wl_display_add_destroy_listener(display, &a->listener);
+ wl_display_add_destroy_listener(display, &b->listener);
+
+ wl_display_destroy(display);
+}
--
2.16.2
More information about the wayland-devel
mailing list