Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1272958

[PATCH v2] tools: ffs-aio-example: clean up upon failure

From Wei Jiangang <weijg.fnst@cn.fujitsu.com>
Newsgroups linux.kernel
Subject [PATCH v2] tools: ffs-aio-example: clean up upon failure
Date 2015-11-19 10:30 +0100
Message-ID <qwtHs-7r8-9@gated-at.bofh.it> (permalink)
References <qw7xg-17g-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Free buffer to avoid memory leak and close fd upon failure occurs.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
---
 tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c | 6 ++++++
 tools/usb/ffs-aio-example/simple/device_app/aio_simple.c       | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c b/tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
index aaca1f44e788..c08b1b0f7a6b 100644
--- a/tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
+++ b/tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
@@ -263,20 +263,26 @@ int main(int argc, char *argv[])
 	sprintf(ep_path, "%s/ep0", argv[1]);
 	ep0 = open(ep_path, O_RDWR);
 	if (ep0 < 0) {
+		free(ep_path);
 		perror("unable to open ep0");
 		return 1;
 	}
 	if (write(ep0, &descriptors, sizeof(descriptors)) < 0) {
+		close(ep0);
+		free(ep_path);
 		perror("unable do write descriptors");
 		return 1;
 	}
 	if (write(ep0, &strings, sizeof(strings)) < 0) {
+		close(ep0);
+		free(ep_path);
 		perror("unable to write strings");
 		return 1;
 	}
 	sprintf(ep_path, "%s/ep1", argv[1]);
 	ep1 = open(ep_path, O_RDWR);
 	if (ep1 < 0) {
+		free(ep_path);
 		perror("unable to open ep1");
 		return 1;
 	}
diff --git a/tools/usb/ffs-aio-example/simple/device_app/aio_simple.c b/tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
index 1f44a29818bf..9ff657ed0bec 100644
--- a/tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
+++ b/tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
@@ -234,14 +234,19 @@ int main(int argc, char *argv[])
 	sprintf(ep_path, "%s/ep0", argv[1]);
 	ep0 = open(ep_path, O_RDWR);
 	if (ep0 < 0) {
+		free(ep_path);
 		perror("unable to open ep0");
 		return 1;
 	}
 	if (write(ep0, &descriptors, sizeof(descriptors)) < 0) {
+		close(ep0);
+		free(ep_path);
 		perror("unable do write descriptors");
 		return 1;
 	}
 	if (write(ep0, &strings, sizeof(strings)) < 0) {
+		close(ep0);
+		free(ep_path);
 		perror("unable to write strings");
 		return 1;
 	}
@@ -249,6 +254,7 @@ int main(int argc, char *argv[])
 		sprintf(ep_path, "%s/ep%d", argv[1], i+1);
 		ep[i] = open(ep_path, O_RDWR);
 		if (ep[i] < 0) {
+			free(ep_path);
 			printf("unable to open ep%d: %s\n", i+1,
 			       strerror(errno));
 			return 1;
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH] tools: ffs-aio-example: free memory upon failure "Wei, Jiangang" <weijg.fnst@cn.fujitsu.com> - 2015-11-18 07:20 +0100
  Re: [PATCH] tools: ffs-aio-example: free memory upon failure Robert Baldyga <r.baldyga@samsung.com> - 2015-11-18 10:50 +0100
    [PATCH v2] tools: ffs-aio-example: clean up upon failure Wei Jiangang <weijg.fnst@cn.fujitsu.com> - 2015-11-19 10:30 +0100
    Re: [PATCH] tools: ffs-aio-example: free memory upon failure "Wei, Jiangang" <weijg.fnst@cn.fujitsu.com> - 2015-11-19 10:40 +0100

csiph-web