]> git.draconx.ca Git - gentoo-fixes.git/blob - media-sound/apulse/files/check-key-before-remove.patch
app-emulation/wine-vanilla-4.0.4: Adapt mpg123 dependency.
[gentoo-fixes.git] / media-sound / apulse / files / check-key-before-remove.patch
1 From bf146f0d711ce3e48cdc8ba772039d843d590b47 Mon Sep 17 00:00:00 2001
2 From: "Miouyouyou (Myy)" <myy@miouyouyou.fr>
3 Date: Sun, 20 Oct 2019 05:09:29 +0200
4 Subject: [PATCH] stream: Check the key before invoking g_hash_table_remove
5
6 Turns out that I hit a bug where pa_stream_unref would
7 call g_hash_table_remove with a NULL key.
8
9 Thanks for the lightweight and smooth error handling from
10 Glib, g_hash_table_remove generated an ABORT call, crashing
11 some Unity3D games I was trying to start.
12 Now, you also CANNOT call g_hash_table_lookup with a NULL
13 key. That also generate a crash... Ugh...
14
15 So, yeah, we first check that the key is not 0, then check
16 if the key is actually inside the Hash table and THEN remove
17 it.
18
19 Note, here's my ~/.asoundrc, just in case :
20 defaults.pcm.!card Audio
21 defaults.ctl.!card Audio
22
23 Audio being :
24 card 3: Audio [DigiHug USB Audio], device 0: USB Audio [USB Audio]
25   Subdevices: 0/1
26   Subdevice #0: subdevice #0
27 card 3: Audio [DigiHug USB Audio], device 1: USB Audio [USB Audio #1]
28   Subdevices: 1/1
29   Subdevice #0: subdevice #0
30
31 I'm using a FiiO device for sound output.
32
33 Signed-off-by: Miouyouyou (Myy) <myy@miouyouyou.fr>
34 ---
35  src/apulse-stream.c | 6 +++++-
36  1 file changed, 5 insertions(+), 1 deletion(-)
37
38 diff --git a/src/apulse-stream.c b/src/apulse-stream.c
39 index 84b18bb..1de4885 100644
40 --- a/src/apulse-stream.c
41 +++ b/src/apulse-stream.c
42 @@ -1019,7 +1019,11 @@ pa_stream_unref(pa_stream *s)
43  
44      s->ref_cnt--;
45      if (s->ref_cnt == 0) {
46 -        g_hash_table_remove(s->c->streams_ht, GINT_TO_POINTER(s->idx));
47 +        GHashTable * __restrict const streams_ht =
48 +            s->c->streams_ht;
49 +        void const * key = GINT_TO_POINTER(s->idx);
50 +        if (key && g_hash_table_lookup(streams_ht, key))
51 +            g_hash_table_remove(streams_ht, key);
52          ringbuffer_free(s->rb);
53          free(s->peek_buffer);
54          free(s->write_buffer);