Skip to contentSkip to conversation

Fix memory leaks in obex

PATCH Applied Steve Grubb 3 participants 4 messages May 15, 2021 – May 19, 2021 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory leaks in obex

This patch fixes a couple memory leaks.

In filesystem, g_file_get_contents allocates fresh memory to buf. It needs to be freed after conversion to a GString object.

Destination was missed on an error path as is mld.

---
 obexd/plugins/filesystem.c     | 2 +-
 obexd/plugins/ftp.c            | 8 ++++++--
 obexd/plugins/messages-dummy.c | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)
obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, renamed from obexd/plugins/filesystem.c +0 -0
index 09bff8ad0..44e3cf3d2 100644

}

object->buffer = g_string_new(buf);
+ g_free(buf);

if (size)
*size = object->buffer->len;

obexd/plugins/ftp.c +6 -2
index 259bfcae2..4b04bab06 100644
@@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
@@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
obexd/plugins/messages-dummy.c +1 -0
index 34199fa05..e37b52df6 100644
@@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
 			int err = -errno;
 			DBG("fopen(): %d, %s", -err, strerror(-err));
 			g_free(path);
+			g_free(mld);
 			return -EBADR;
 		}
 	}
Signature · 1 line
2.31.1
#1 lore raw

Hi Steve,

obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode,

Quoted 17 lines · Steve Grubb

This patch fixes a couple memory leaks.

In filesystem, g_file_get_contents allocates fresh memory to buf. It needs to be freed after conversion to a GString object.

Destination was missed on an error path as is mld.

---
 obexd/plugins/filesystem.c     | 2 +-
 obexd/plugins/ftp.c            | 8 ++++++--
 obexd/plugins/messages-dummy.c | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)
obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, renamed from obexd/plugins/filesystem.c +0 -0
index 09bff8ad0..44e3cf3d2 100644

CI wasn't able to apply the patch and couldn't run the tests, and I think because of this line.

Quoted 47 lines
obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, renamed from obexd/plugins/filesystem.c +1 -0
 		}
 
 		object->buffer = g_string_new(buf);
+		g_free(buf);
 
 		if (size)
 			*size = object->buffer->len;
obexd/plugins/ftp.c +6 -2
index 259bfcae2..4b04bab06 100644
@@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
@@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
obexd/plugins/messages-dummy.c +1 -0
index 34199fa05..e37b52df6 100644
@@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
 			int err = -errno;
 			DBG("fopen(): %d, %s", -err, strerror(-err));
 			g_free(path);
+			g_free(mld);
 			return -EBADR;
 		}
 	}
#2 lore raw
Quoted 14 lines · EDT Tedd Ho-Jeong An
Quoted 13 lines · Steve Grubb

This patch fixes a couple memory leaks.

In filesystem, g_file_get_contents allocates fresh memory to buf. It needs to be freed after conversion to a GString object.

Destination was missed on an error path as is mld.

---

obexd/plugins/filesystem.c     | 2 +-
obexd/plugins/ftp.c            | 8 ++++++--
obexd/plugins/messages-dummy.c | 1 +
3 files changed, 8 insertions(+), 3 deletions(-)
Quoted 8 lines
Quoted 5 lines
obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void renamed from obexd/plugins/filesystem.c +0 -0
index 09bff8ad0..44e3cf3d2 100644

*capability_open(const char *name, int oflag, mode_t mode,

CI wasn't able to apply the patch and couldn't run the tests, and I think because of this line.

Hmm. Apologies. I'll regenerate the patch and send it again.

Cheers,
-Steve

maintainer Applied
#3 lore raw
In reply to Steve Grubb

Hi Steve,

Quoted 66 lines · Steve Grubb

This patch fixes a couple memory leaks.

In filesystem, g_file_get_contents allocates fresh memory to buf. It needs to be freed after conversion to a GString object.

Destination was missed on an error path as is mld.

---
 obexd/plugins/filesystem.c     | 2 +-
 obexd/plugins/ftp.c            | 8 ++++++--
 obexd/plugins/messages-dummy.c | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)
obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, renamed from obexd/plugins/filesystem.c +1 -0
index 09bff8ad0..44e3cf3d2 100644
                }
 
                object->buffer = g_string_new(buf);
+               g_free(buf);
 
                if (size)
                        *size = object->buffer->len;
obexd/plugins/ftp.c +6 -2
index 259bfcae2..4b04bab06 100644
@@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
        ret = verify_path(destdir);
        g_free(destdir);
 
-       if (ret < 0)
+       if (ret < 0) {
+               g_free(destination);
                return ret;
+       }
 
        source = g_build_filename(ftp->folder, name, NULL);
 
@@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
        ret = verify_path(destdir);
        g_free(destdir);
 
-       if (ret < 0)
+       if (ret < 0) {
+               g_free(destination);
                return ret;
+       }
 
        source = g_build_filename(ftp->folder, name, NULL);
 
obexd/plugins/messages-dummy.c +1 -1
index 34199fa05..e37b52df6 100644
@@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
                        int err = -errno;
                        DBG("fopen(): %d, %s", -err, strerror(-err));
                        g_free(path);
+                       g_free(mld);
                        return -EBADR;
                }
        }
--
Quoted 1 line

2.31.1

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz