After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 711751 - Fix memory leaks in libglib tests
Fix memory leaks in libglib tests
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 711744
 
 
Reported: 2013-11-09 23:38 UTC by Stef Walter
Modified: 2013-12-16 00:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
private: Fix memory leak in tests (1.29 KB, patch)
2013-11-09 23:51 UTC, Stef Walter
committed Details | Review
gerror: Don't leak memory when overwrite warning (1.63 KB, patch)
2013-11-09 23:56 UTC, Stef Walter
committed Details | Review
unix: Fix memory leak in unix test (736 bytes, patch)
2013-11-09 23:57 UTC, Stef Walter
committed Details | Review
asyncqueue-test: Fix leaks in tests (764 bytes, patch)
2013-11-09 23:59 UTC, Stef Walter
committed Details | Review
child-test: Fix leak in test (654 bytes, patch)
2013-11-09 23:59 UTC, Stef Walter
committed Details | Review
completion-test: Fix leaks in tests (1.01 KB, patch)
2013-11-10 00:00 UTC, Stef Walter
committed Details | Review
gio-test: Fix leaks in tests (1.01 KB, patch)
2013-11-10 00:00 UTC, Stef Walter
committed Details | Review
mainloop-test: Fix uninitialized memory access in tests (949 bytes, patch)
2013-11-10 00:00 UTC, Stef Walter
committed Details | Review
mapping-test: Fix leaks in tests (1.03 KB, patch)
2013-11-10 00:00 UTC, Stef Walter
committed Details | Review
sources: Fix leaks in tests (1.53 KB, patch)
2013-11-10 00:02 UTC, Stef Walter
committed Details | Review
datetime: Fix leak in test (611 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
file-test: Fix leaks in test (968 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
mainloop-test: Fix leaks in tests (852 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
thread-test: Fix leaks in tests (973 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
timeloop: Fix leaks in tests (911 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
unicode-encoding: Fix leaks in test (661 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
committed Details | Review
threadpool-test: Fix leaks in tests (982 bytes, patch)
2013-11-10 00:03 UTC, Stef Walter
none Details | Review
iochannel-test: Fix leaks in test (700 bytes, patch)
2013-11-10 10:05 UTC, Stef Walter
committed Details | Review
threadpool-test: Fix leaks in tests (982 bytes, patch)
2013-11-10 10:21 UTC, Stef Walter
reviewed Details | Review
threadpool-test: Fix leaks in tests (712 bytes, patch)
2013-11-11 07:04 UTC, Stef Walter
committed Details | Review

Description Stef Walter 2013-11-09 23:38:32 UTC
In order to make libglib tests be valgrindable, I'll post a bunch of patches which fix memory leaks there.

In general it's good practice to free stuff in tests, so that we can run through those code paths, and make sure we received appropriate references/memory.
Comment 1 Stef Walter 2013-11-09 23:51:39 UTC
Created attachment 259366 [details] [review]
private: Fix memory leak in tests

Don't use g_private_new(), it's deprecated, and leaks by definition.
Comment 2 Stef Walter 2013-11-09 23:56:33 UTC
Created attachment 259369 [details] [review]
gerror: Don't leak memory when overwrite warning

Even though we can't always make no-leak guarantees when g_warning()
in this case we're testing this behavior in tests, and it would be
good to be able to valgrind this.
Comment 3 Stef Walter 2013-11-09 23:57:45 UTC
Created attachment 259371 [details] [review]
unix: Fix memory leak in unix test
Comment 4 Stef Walter 2013-11-09 23:59:02 UTC
Created attachment 259373 [details] [review]
asyncqueue-test: Fix leaks in tests
Comment 5 Stef Walter 2013-11-09 23:59:41 UTC
Created attachment 259374 [details] [review]
child-test: Fix leak in test
Comment 6 Stef Walter 2013-11-10 00:00:33 UTC
Created attachment 259375 [details] [review]
completion-test: Fix leaks in tests
Comment 7 Stef Walter 2013-11-10 00:00:37 UTC
Created attachment 259376 [details] [review]
gio-test: Fix leaks in tests
Comment 8 Stef Walter 2013-11-10 00:00:42 UTC
Created attachment 259377 [details] [review]
mainloop-test: Fix uninitialized memory access in tests
Comment 9 Stef Walter 2013-11-10 00:00:46 UTC
Created attachment 259378 [details] [review]
mapping-test: Fix leaks in tests
Comment 10 Stef Walter 2013-11-10 00:02:56 UTC
Created attachment 259380 [details] [review]
sources: Fix leaks in tests
Comment 11 Stef Walter 2013-11-10 00:03:00 UTC
Created attachment 259381 [details] [review]
datetime: Fix leak in test
Comment 12 Stef Walter 2013-11-10 00:03:04 UTC
Created attachment 259382 [details] [review]
file-test: Fix leaks in test
Comment 13 Stef Walter 2013-11-10 00:03:09 UTC
Created attachment 259383 [details] [review]
mainloop-test: Fix leaks in tests
Comment 14 Stef Walter 2013-11-10 00:03:14 UTC
Created attachment 259384 [details] [review]
thread-test: Fix leaks in tests

This is a test of deprecated functionality and its age is
showing. Doesn't actually do what it says. But fix leaks anyway.
Comment 15 Stef Walter 2013-11-10 00:03:19 UTC
Created attachment 259385 [details] [review]
timeloop: Fix leaks in tests
Comment 16 Stef Walter 2013-11-10 00:03:24 UTC
Created attachment 259386 [details] [review]
unicode-encoding: Fix leaks in test
Comment 17 Stef Walter 2013-11-10 00:03:29 UTC
Created attachment 259387 [details] [review]
threadpool-test: Fix leaks in tests
Comment 18 Stef Walter 2013-11-10 10:05:07 UTC
Created attachment 259410 [details] [review]
iochannel-test: Fix leaks in test
Comment 19 Stef Walter 2013-11-10 10:21:35 UTC
Created attachment 259411 [details] [review]
threadpool-test: Fix leaks in tests
Comment 20 Colin Walters 2013-11-10 15:11:03 UTC
Review of attachment 259411 [details] [review]:

::: tests/threadpool-test.c
@@ +247,3 @@
+{
+  g_thread_pool_free (pool, FALSE, TRUE);
+}

I'm confused, this function appears to be unused in your patch?
Comment 21 Colin Walters 2013-11-10 15:13:10 UTC
Review of attachment 259366 [details] [review]:

Looks right.
Comment 22 Colin Walters 2013-11-10 15:16:07 UTC
Review of attachment 259369 [details] [review]:

Ok.
Comment 23 Colin Walters 2013-11-10 15:16:26 UTC
Review of attachment 259371 [details] [review]:

Yep.
Comment 24 Colin Walters 2013-11-10 15:17:38 UTC
Review of attachment 259373 [details] [review]:

At some point we should do a mass-porting away from GMainLoop to the new while () { GMainContext.iteration(); } pattern.  Doesn't make sense to conflate that with these fixes, just noticing leaking GMainLoop is quite common.
Comment 25 Colin Walters 2013-11-10 15:17:53 UTC
Review of attachment 259374 [details] [review]:

Yep.
Comment 26 Colin Walters 2013-11-10 15:18:57 UTC
Review of attachment 259375 [details] [review]:

Looks correct.
Comment 27 Colin Walters 2013-11-10 15:20:17 UTC
Review of attachment 259376 [details] [review]:

Holy cow this is some ugly code...not your fault =)  Anyways looks right.
Comment 28 Colin Walters 2013-11-10 15:22:03 UTC
Review of attachment 259377 [details] [review]:

::: tests/mainloop-test.c
@@ +221,2 @@
   sprintf (buf1, "%d", a);
   sprintf (buf2, "%d", b);

Are you sure this hunk is necessary?
Comment 29 Colin Walters 2013-11-10 15:22:41 UTC
Review of attachment 259378 [details] [review]:

g_free() all the things!
Comment 30 Colin Walters 2013-11-10 15:25:51 UTC
Review of attachment 259380 [details] [review]:

::: tests/sources.c
@@ +107,3 @@
+    {
+      g_source_destroy (sources[i]);
+      g_source_unref (sources[i]);

Are you sure you're not double-unreffing here?  We're transferring ownership of the source to the worker thread, which per your above hunk will attach then call _unref(), so now the context owns one ref.
Comment 31 Colin Walters 2013-11-10 15:26:05 UTC
Review of attachment 259381 [details] [review]:

Yep.
Comment 32 Colin Walters 2013-11-10 15:27:06 UTC
Review of attachment 259382 [details] [review]:

::: tests/file-test.c
@@ +185,3 @@
   g_assert (data == NULL && "could read link3");
   g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
+  g_error_free (error);

You could use g_clear_error () and also remove the subsequent line.

Personally in my code, I much prefer g_clear_error() since it's much easier to confidently later add code.
Comment 33 Colin Walters 2013-11-10 15:27:55 UTC
Review of attachment 259383 [details] [review]:

Ok.
Comment 34 Colin Walters 2013-11-10 15:28:50 UTC
Review of attachment 259384 [details] [review]:

I'm not going to dive into this one...I'll trust you on it.
Comment 35 Colin Walters 2013-11-10 15:31:11 UTC
Review of attachment 259385 [details] [review]:

::: tests/timeloop.c
@@ +154,3 @@
 		      input_callback, in_channels[1]);
+      g_io_channel_unref (in_channels[0]);
+      g_io_channel_unref (out_channels[1]);

This is a really minor comment, but wouldn't it make more sense to have the _unref() calls next to the corresponding close() calls?  Really there should be g_io_channel_close_and_unref () or something.  But anyways, feel free to ignore this too.
Comment 36 Colin Walters 2013-11-10 15:31:46 UTC
Review of attachment 259386 [details] [review]:

Looks right.
Comment 37 Colin Walters 2013-11-10 15:32:01 UTC
Review of attachment 259410 [details] [review]:

Ok.
Comment 38 Stef Walter 2013-11-10 21:51:08 UTC
Thanks for the reviews. Merging these. Will answer and rework others later...

Attachment 259366 [details] pushed as e74b435 - private: Fix memory leak in tests
Attachment 259369 [details] pushed as ab3c554 - gerror: Don't leak memory when overwrite warning
Attachment 259371 [details] pushed as e525586 - unix: Fix memory leak in unix test
Attachment 259373 [details] pushed as 9a67fb9 - asyncqueue-test: Fix leaks in tests
Attachment 259374 [details] pushed as ba56c7b - child-test: Fix leak in test
Attachment 259375 [details] pushed as ee74367 - completion-test: Fix leaks in tests
Attachment 259376 [details] pushed as fc4630b - gio-test: Fix leaks in tests
Attachment 259378 [details] pushed as 5ae5d43 - mapping-test: Fix leaks in tests
Attachment 259381 [details] pushed as 83a14d1 - datetime: Fix leak in test
Attachment 259383 [details] pushed as ae1764b - mainloop-test: Fix leaks in tests
Attachment 259384 [details] pushed as e8cc096 - thread-test: Fix leaks in tests
Attachment 259386 [details] pushed as 44bd2ab - unicode-encoding: Fix leaks in test
Attachment 259410 [details] pushed as 0a02fd9 - iochannel-test: Fix leaks in test
Comment 39 Stef Walter 2013-11-11 07:03:46 UTC
Review of attachment 259411 [details] [review]:

::: tests/threadpool-test.c
@@ +247,3 @@
+{
+  g_thread_pool_free (pool, FALSE, TRUE);
+}

Indeed. Removed
Comment 40 Stef Walter 2013-11-11 07:04:04 UTC
Created attachment 259525 [details] [review]
threadpool-test: Fix leaks in tests
Comment 41 Stef Walter 2013-11-11 07:05:09 UTC
Review of attachment 259377 [details] [review]:

::: tests/mainloop-test.c
@@ +221,2 @@
   sprintf (buf1, "%d", a);
   sprintf (buf2, "%d", b);

Yes, because the entire buffer is written.
Comment 42 Stef Walter 2013-11-11 07:09:27 UTC
Review of attachment 259380 [details] [review]:

::: tests/sources.c
@@ +107,3 @@
+    {
+      g_source_destroy (sources[i]);
+      g_source_unref (sources[i]);

Hmmm the test is confusing, but both of these g_source_unref() hunks happen before threads get involved. The threading stuff happens below.
Comment 43 Stef Walter 2013-11-11 07:11:18 UTC
Review of attachment 259382 [details] [review]:

::: tests/file-test.c
@@ +185,3 @@
   g_assert (data == NULL && "could read link3");
   g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
+  g_error_free (error);

Indeed. But that's the style of the rest of the test, so I just went with the flow.
Comment 44 Stef Walter 2013-11-11 07:11:50 UTC
Comment on attachment 259382 [details] [review]
file-test: Fix leaks in test

Attachment 259382 [details] pushed as 9e0ade0 - file-test: Fix leaks in test
Comment 45 Stef Walter 2013-11-11 07:15:10 UTC
(In reply to comment #35)
> This is a really minor comment, but wouldn't it make more sense to have the
> _unref() calls next to the corresponding close() calls?  Really there should be
> g_io_channel_close_and_unref () or something.  But anyways, feel free to ignore
> this too.

Done and merged.
Comment 46 Stef Walter 2013-11-11 07:16:03 UTC
Comment on attachment 259385 [details] [review]
timeloop: Fix leaks in tests

Attachment 259385 [details] pushed as 177fe9f - timeloop: Fix leaks in tests
Comment 47 Colin Walters 2013-11-11 16:00:30 UTC
Review of attachment 259377 [details] [review]:

Oh I see.  Looks right then, thanks!
Comment 48 Colin Walters 2013-11-11 16:29:28 UTC
Review of attachment 259525 [details] [review]:

Right.
Comment 49 Stef Walter 2013-11-11 16:39:21 UTC
Attachment 259377 [details] pushed as 3e041ce - mainloop-test: Fix uninitialized memory access in tests
Attachment 259525 [details] pushed as d10f353 - threadpool-test: Fix leaks in tests
Comment 50 Matthias Clasen 2013-12-16 00:30:13 UTC
Attachment 259380 [details] pushed as 3f8888d - sources: Fix leaks in tests