[tracker] Thunderbird: Fix memory leak in TrackerStore.escapeString



commit adbe5199a71e2ef39285d70a9dfceaa7d38c3086
Author: Adrien Bustany <adrien bustany nokia com>
Date:   Mon Aug 1 10:12:13 2011 +0300

    Thunderbird: Fix memory leak in TrackerStore.escapeString
    
    When getting C strings through CTypes, the memory has to be freed
    manually.

 src/plugins/thunderbird/chrome/content/bindings.js |    7 +++++++
 .../thunderbird/chrome/content/trackerstore.js     |    6 +++++-
 2 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/src/plugins/thunderbird/chrome/content/bindings.js b/src/plugins/thunderbird/chrome/content/bindings.js
index 5ae6d0b..d253bdf 100644
--- a/src/plugins/thunderbird/chrome/content/bindings.js
+++ b/src/plugins/thunderbird/chrome/content/bindings.js
@@ -41,6 +41,13 @@ org.bustany.TrackerBird.TrackerSparql = {
 		tracker.Cursor = ctypes.StructType ("TrackerSparqlCursor");
 
 		// GLib methods
+		tracker.free = tracker._lib.declare (
+			"g_free",
+			ctypes.default_abi,
+			ctypes.void_t,
+			ctypes.void_t.ptr
+		);
+
 		tracker.object_unref = tracker._lib.declare (
 			"g_object_unref",
 			ctypes.default_abi,
diff --git a/src/plugins/thunderbird/chrome/content/trackerstore.js b/src/plugins/thunderbird/chrome/content/trackerstore.js
index 50e8c4f..ee60371 100644
--- a/src/plugins/thunderbird/chrome/content/trackerstore.js
+++ b/src/plugins/thunderbird/chrome/content/trackerstore.js
@@ -156,7 +156,11 @@ org.bustany.TrackerBird.TrackerStore = {
 	},
 
 	escapeString: function(str) {
-		return this._tracker.escape_string(str).readString();
+		var cstr = this._tracker.escape_string(str);
+		var escaped = cstr.readString();
+		this._tracker.free(cstr);
+
+		return escaped;
 	},
 
 	insertEmailAddress: function(address) {



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