From c090cd50587364016e8c8f8b3831460afeb435f5 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 11 Aug 2020 10:03:14 +0200 Subject: [PATCH] tests: Don't rely on undefined use-after-free behaviour of glibc Makes this check work with musl >= 1.2.1 https://bugzilla.gnome.org/show_bug.cgi?id=736774 --- tests/control-flow/bug736774-1.vala | 6 +++--- tests/control-flow/bug736774-2.vala | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/control-flow/bug736774-1.vala b/tests/control-flow/bug736774-1.vala index 1fd70a40e..db6c66fac 100644 --- a/tests/control-flow/bug736774-1.vala +++ b/tests/control-flow/bug736774-1.vala @@ -1,8 +1,8 @@ -bool success = false; +int success = 0; class Foo : Object { ~Foo() { - success = true; + success++; } } @@ -19,5 +19,5 @@ void main() { } catch { } - assert (success); + assert (success == 1); } diff --git a/tests/control-flow/bug736774-2.vala b/tests/control-flow/bug736774-2.vala index f54ce5cbd..a7d983f96 100644 --- a/tests/control-flow/bug736774-2.vala +++ b/tests/control-flow/bug736774-2.vala @@ -1,8 +1,20 @@ -string* keep; +int success = 0; -string may_fail () throws GLib.Error { - string result = "test"; - keep = result; +[Compact] +[Immutable] +[CCode (free_function = "vstring_destroy")] +public class vstring : string { + public vstring (string s); + + [DestroysInstance] + public void destroy () { + free (this); + success++; + } +} + +vstring may_fail () throws GLib.Error { + vstring result = (vstring) "test".dup (); return (owned) result; } @@ -12,5 +24,5 @@ void main () { } catch { } - assert (keep != "test"); + assert (success == 1); } -- 2.47.2