[libsoup/gnome-3-28] socket-properties: Implement MT-safe refcounting



commit 031fb9249b419f6e02108273c964c1224d8d15c1
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]