[libsoup] socket-properties: Implement MT-safe refcounting
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] socket-properties: Implement MT-safe refcounting
- Date: Wed, 20 Jun 2018 15:34:55 +0000 (UTC)
commit d6224cc932c52f829a591a408fccbde68573cbda
Author: Edward Hervey <edward centricular com>
Date: Wed Jun 20 11:46:40 2018 +0200
socket-properties: Implement MT-safe refcounting
Use atomic integer operation when dealing with refcounting, otherwise
one could very easily end-up in leaked (bad) properties or
double-freed (really bad) properties.
libsoup/soup-socket-properties.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-socket-properties.c b/libsoup/soup-socket-properties.c
index 8dea78c6..3c99be73 100644
--- a/libsoup/soup-socket-properties.c
+++ b/libsoup/soup-socket-properties.c
@@ -45,14 +45,14 @@ soup_socket_properties_new (GMainContext *async_context,
SoupSocketProperties *
soup_socket_properties_ref (SoupSocketProperties *props)
{
- props->ref_count++;
+ g_atomic_int_inc (&props->ref_count);
return props;
}
void
soup_socket_properties_unref (SoupSocketProperties *props)
{
- if (--props->ref_count)
+ if (!g_atomic_int_dec_and_test (&props->ref_count))
return;
g_clear_pointer (&props->async_context, g_main_context_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]