GNOME Bugzilla – Bug 769224
Memory leak in InputVector.buffer
Last modified: 2018-05-22 15:37:55 UTC
Please consider the following piece of code: class Test { private void on_read(Socket socket) { InputVector[] input_vectors = { InputVector() { buffer = new uint8[64], size = 64 }, }; } public static void main(string[] argv) { } } valac 0.32.1 will produce the following piece of code static void test_on_read (Test* self, GSocket* socket) { GInputVector* input_vectors = NULL; guint8* _tmp0_ = NULL; GInputVector _tmp1_ = {0}; GInputVector* _tmp2_ = NULL; gint input_vectors_length1 = 0; gint _input_vectors_size_ = 0; g_return_if_fail (self != NULL); g_return_if_fail (socket != NULL); _tmp0_ = g_new0 (guint8, 64); memset (&_tmp1_, 0, sizeof (GInputVector)); _tmp1_.buffer = _tmp0_; _tmp1_.size = (gsize) 64; _tmp2_ = g_new0 (GInputVector, 1); _tmp2_[0] = _tmp1_; input_vectors = _tmp2_; input_vectors_length1 = 1; _input_vectors_size_ = input_vectors_length1; input_vectors = (g_free (input_vectors), NULL); } _tmp0_ is never deallocated probably the same apply to OutputVector
Refactoring code to class Test { private void on_read(Socket socket) { uint8[] buffer1 = new uint8[64]; InputVector[] input_vectors = { InputVector() { buffer = buffer1, size = 64 }, }; } public static void main(string[] argv) { } } causes buffer to be properly deallocated.
This is quite expected since the In/OutputVector.buffer is defined as "void*" which is a pointer and therefore not managed by vala's memory management. The bindings of InputMessage, InputVector, OutputMessage and OutputVector should be fixed to account for this.
Created attachment 337260 [details] [review] gio-2.0: Fix InputMessage, InputVector, OutputMessage and OutputVector
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/550.