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 769224 - Memory leak in InputVector.buffer
Memory leak in InputVector.buffer
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Bindings: GLib
0.32.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-07-27 13:08 UTC by Marcin Lewandowski
Modified: 2018-05-22 15:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio-2.0: Fix InputMessage, InputVector, OutputMessage and OutputVector (3.18 KB, patch)
2016-10-09 08:51 UTC, Rico Tzschichholz
none Details | Review

Description Marcin Lewandowski 2016-07-27 13:08:00 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
Comment 1 Marcin Lewandowski 2016-07-27 13:11:35 UTC
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.
Comment 2 Rico Tzschichholz 2016-09-18 14:18:53 UTC
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.
Comment 3 Rico Tzschichholz 2016-10-09 08:51:41 UTC
Created attachment 337260 [details] [review]
gio-2.0: Fix InputMessage, InputVector, OutputMessage and OutputVector
Comment 4 GNOME Infrastructure Team 2018-05-22 15:37:55 UTC
-- 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.