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
6 Turns out that I hit a bug where pa_stream_unref would
7 call g_hash_table_remove with a NULL key.
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...
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
19 Note, here's my ~/.asoundrc, just in case :
20 defaults.pcm.!card Audio
21 defaults.ctl.!card Audio
24 card 3: Audio [DigiHug USB Audio], device 0: USB Audio [USB Audio]
26 Subdevice #0: subdevice #0
27 card 3: Audio [DigiHug USB Audio], device 1: USB Audio [USB Audio #1]
29 Subdevice #0: subdevice #0
31 I'm using a FiiO device for sound output.
33 Signed-off-by: Miouyouyou (Myy) <myy@miouyouyou.fr>
35 src/apulse-stream.c | 6 +++++-
36 1 file changed, 5 insertions(+), 1 deletion(-)
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)
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 =
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);
54 free(s->write_buffer);