Diff between c6ee92855d32a61a0b0e8aa399b822faaa7bcac7 and 2330d1a1edd2b4901c3f84a2f589cd5baa34bae5

Changed Files

File Additions Deletions Status
obexd/plugins/filesystem.c +19 -5 modified

Full Patch

diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index 080b771..46fbd8e 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c
@@ -180,6 +180,7 @@ static gpointer capability_open(const char *name, int oflag, mode_t mode,
 	gchar *buf;
 	gint exit;
 	gboolean ret;
+	GString *object;
 
 	if (oflag != O_RDONLY)
 		goto fail;
@@ -207,10 +208,12 @@ static gpointer capability_open(const char *name, int oflag, mode_t mode,
 	}
 
 done:
+	object = g_string_new(buf);
+
 	if (size)
-		*size = strlen(buf);
+		*size = object->len;
 
-	return buf;
+	return object;
 
 fail:
 	if (gerr)
@@ -222,14 +225,25 @@ fail:
 
 static int capability_close(gpointer object)
 {
-	g_free(object);
+	GString *capability = object;
+
+	g_string_free(capability, TRUE);
 	return 0;
 }
 
 static ssize_t capability_read(gpointer object, void *buf, size_t count)
 {
-	strncpy(buf, object, count);
-	return strlen(buf);
+	GString *capability = object;
+	ssize_t len;
+
+	if (capability->len == 0)
+		return 0;
+
+	strncpy(buf, capability->str, count);
+	len = strlen(buf);
+	capability = g_string_erase(capability, 0, len);
+
+	return len;
 }
 
 static gpointer folder_open(const char *name, int oflag, mode_t mode,