The source project of this merge request has been removed.
Fix a memory leak
Hello.
There is a memory leak when exiting xcb.
I'm using FreeBSD 13.
I don't know if memory leak occurs in Linux environment as well.
% more xcb.c
#include <xcb/xcb.h>
#include <stdio.h>
int main ()
{
xcb_connection_t *conn;
conn = xcb_connect (NULL, NULL);
if (xcb_connection_has_error (conn))
{
puts ("error");
return 1;
}
xcb_disconnect (conn);
return 0;
}
% valgrind --leak-check=full ./xcb
==7320== Memcheck, a memory error detector
==7320== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==7320== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==7320== Command: ./xcb
==7320==
==7320==
==7320== HEAP SUMMARY:
==7320== in use at exit: 1,212 bytes in 3 blocks
==7320== total heap usage: 21 allocs, 18 frees, 39,020 bytes allocated
==7320==
==7320== 20 bytes in 1 blocks are definitely lost in loss record 1 of 3
==7320== at 0x4851381: calloc (in /usr/local/libexec/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==7320== by 0x4897343: pthread_cond_init (in /lib/libthr.so.3)
==7320== by 0x4873457: ??? (in /usr/local/lib/libxcb.so.1.1.0)
==7320== by 0x4871E32: xcb_connect_to_fd (in /usr/local/lib/libxcb.so.1.1.0)
==7320== by 0x4875C2E: xcb_connect_to_display_with_auth_info (in /usr/local/lib/libxcb.so.1.1.0)
==7320== by 0x20199D: main (in /usr/home/hodong/projects/samples/xcb)
==7320==
==7320== LEAK SUMMARY:
==7320== definitely lost: 20 bytes in 1 blocks
==7320== indirectly lost: 0 bytes in 0 blocks
==7320== possibly lost: 0 bytes in 0 blocks
==7320== still reachable: 1,192 bytes in 2 blocks
==7320== suppressed: 0 bytes in 0 blocks
==7320== Reachable blocks (those to which a pointer was found) are not shown.
==7320== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7320==
==7320== For lists of detected and suppressed errors, rerun with: -s
==7320== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
I addad pthread_cond_destroy(&out->socket_cond);
And I changed the order in void _xcb_out_destroy(_xcb_out *out)
.
int _xcb_out_init(_xcb_out *out)
A
B
C
void _xcb_out_destroy(_xcb_out *out)
C
B
A