Re: [PATCH] daemon: plug a memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/13/2010 04:20 PM, Matthias Bolte wrote:
> 2010/12/13 Eric Blake <eblake@xxxxxxxxxx>:
>> * daemon/libvirtd.c (qemudStartWorker, qemudStartEventLoop): Avoid
>> leaking pthread_attr resources.
>> ---
>>  daemon/libvirtd.c |   36 ++++++++++++++++++++++++++----------
>>  1 files changed, 26 insertions(+), 10 deletions(-)
>>
> 
> ACK.

Thanks.  Hmm, src/util/threads-pthread.c had the same leak; I'm
squashing this in, then pushing.

diff --git i/src/util/threads-pthread.c w/src/util/threads-pthread.c
index c406f27..1653396 100644
--- i/src/util/threads-pthread.c
+++ w/src/util/threads-pthread.c
@@ -157,9 +157,15 @@ int virThreadCreate(virThreadPtr thread,
 {
     struct virThreadArgs *args;
     pthread_attr_t attr;
-    pthread_attr_init(&attr);
-    if (VIR_ALLOC(args) < 0)
+    int ret = -1;
+    int err;
+
+    if ((err = pthread_attr_init(&attr)) != 0)
         goto cleanup;
+    if (VIR_ALLOC(args) < 0) {
+        err = ENOMEM;
+        goto cleanup;
+    }

     args->func = func;
     args->opaque = opaque;
@@ -167,14 +173,19 @@ int virThreadCreate(virThreadPtr thread,
     if (!joinable)
         pthread_attr_setdetachstate(&attr, 1);

-    int ret = pthread_create(&thread->thread, &attr, virThreadHelper,
args);
-    if (ret != 0) {
+    err = pthread_create(&thread->thread, &attr, virThreadHelper, args);
+    if (err != 0) {
         VIR_FREE(args);
-        errno = ret;
-        return -1;
+        goto cleanup;
     }
     /* New thread owns 'args' in success case, so don't free */
-    return 0;
+
+    ret = 0;
+cleanup:
+    pthread_attr_destroy(&attr);
+    if (ret < 0)
+        errno = err;
+    return ret;
 }

 void virThreadSelf(virThreadPtr thread)


-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]