* [PATCH] tools: ffs-aio-example: free memory upon failure
@ 2015-11-09 6:16 Wei Jiangang
2015-11-18 6:13 ` Wei, Jiangang
0 siblings, 1 reply; 5+ messages in thread
From: Wei Jiangang @ 2015-11-09 6:16 UTC (permalink / raw)
To: standby24x7, rdunlap, jkosina, balbi, r.baldyga, weijg.fnst; +Cc: linux-kernel
Free buffer to avoid memory leak upon failure occurs.
Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
---
tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c | 4 ++++
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c | 4 ++++
2 files changed, 8 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..3eb1a92baacf 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,24 @@ 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) {
+ free(ep_path);
perror("unable do write descriptors");
return 1;
}
if (write(ep0, &strings, sizeof(strings)) < 0) {
+ 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..ac96892ca5d2 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,17 @@ 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) {
+ free(ep_path);
perror("unable do write descriptors");
return 1;
}
if (write(ep0, &strings, sizeof(strings)) < 0) {
+ free(ep_path);
perror("unable to write strings");
return 1;
}
@@ -249,6 +252,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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] tools: ffs-aio-example: free memory upon failure
2015-11-09 6:16 [PATCH] tools: ffs-aio-example: free memory upon failure Wei Jiangang
@ 2015-11-18 6:13 ` Wei, Jiangang
2015-11-18 9:46 ` Robert Baldyga
0 siblings, 1 reply; 5+ messages in thread
From: Wei, Jiangang @ 2015-11-18 6:13 UTC (permalink / raw)
To: standby24x7; +Cc: r.baldyga, rdunlap, linux-kernel, balbi, jkosina
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2715 bytes --]
To whom it may concernï¼
Sorry to bother again,
But any comment about this patchï¼
Regards,
wei
On Mon, 2015-11-09 at 14:16 +0800, Wei Jiangang wrote:
> Free buffer to avoid memory leak upon failure occurs.
>
> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
> ---
> tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c | 4 ++++
> tools/usb/ffs-aio-example/simple/device_app/aio_simple.c | 4 ++++
> 2 files changed, 8 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..3eb1a92baacf 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,24 @@ 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) {
> + free(ep_path);
> perror("unable do write descriptors");
> return 1;
> }
> if (write(ep0, &strings, sizeof(strings)) < 0) {
> + 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..ac96892ca5d2 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,17 @@ 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) {
> + free(ep_path);
> perror("unable do write descriptors");
> return 1;
> }
> if (write(ep0, &strings, sizeof(strings)) < 0) {
> + free(ep_path);
> perror("unable to write strings");
> return 1;
> }
> @@ -249,6 +252,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;
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tools: ffs-aio-example: free memory upon failure
2015-11-18 6:13 ` Wei, Jiangang
@ 2015-11-18 9:46 ` Robert Baldyga
2015-11-19 9:26 ` [PATCH v2] tools: ffs-aio-example: clean up " Wei Jiangang
2015-11-19 9:30 ` [PATCH] tools: ffs-aio-example: free memory " Wei, Jiangang
0 siblings, 2 replies; 5+ messages in thread
From: Robert Baldyga @ 2015-11-18 9:46 UTC (permalink / raw)
To: Wei, Jiangang, standby24x7; +Cc: rdunlap, linux-kernel, balbi, jkosina
Hi Wei,
On 11/18/2015 07:13 AM, Wei, Jiangang wrote:
> To whom it may concern:
>
> Sorry to bother again,
> But any comment about this patch?
>
Reviewed-by: Robert Baldyga <r.baldyga@samsung.com>
It looks good to me. By the way, maybe we should also close file
descriptors in error path?
Thanks,
Robert Baldyga
> On Mon, 2015-11-09 at 14:16 +0800, Wei Jiangang wrote:
>> Free buffer to avoid memory leak upon failure occurs.
>>
>> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
>> ---
>> tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c | 4 ++++
>> tools/usb/ffs-aio-example/simple/device_app/aio_simple.c | 4 ++++
>> 2 files changed, 8 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..3eb1a92baacf 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,24 @@ 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) {
>> + free(ep_path);
>> perror("unable do write descriptors");
>> return 1;
>> }
>> if (write(ep0, &strings, sizeof(strings)) < 0) {
>> + 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..ac96892ca5d2 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,17 @@ 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) {
>> + free(ep_path);
>> perror("unable do write descriptors");
>> return 1;
>> }
>> if (write(ep0, &strings, sizeof(strings)) < 0) {
>> + free(ep_path);
>> perror("unable to write strings");
>> return 1;
>> }
>> @@ -249,6 +252,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;
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] tools: ffs-aio-example: clean up upon failure
2015-11-18 9:46 ` Robert Baldyga
@ 2015-11-19 9:26 ` Wei Jiangang
2015-11-19 9:30 ` [PATCH] tools: ffs-aio-example: free memory " Wei, Jiangang
1 sibling, 0 replies; 5+ messages in thread
From: Wei Jiangang @ 2015-11-19 9:26 UTC (permalink / raw)
To: r.baldyga; +Cc: standby24x7, rdunlap, balbi, jkosina, weijg.fnst, linux-kernel
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] tools: ffs-aio-example: free memory upon failure
2015-11-18 9:46 ` Robert Baldyga
2015-11-19 9:26 ` [PATCH v2] tools: ffs-aio-example: clean up " Wei Jiangang
@ 2015-11-19 9:30 ` Wei, Jiangang
1 sibling, 0 replies; 5+ messages in thread
From: Wei, Jiangang @ 2015-11-19 9:30 UTC (permalink / raw)
To: r.baldyga; +Cc: standby24x7, rdunlap, balbi, linux-kernel, jkosina
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3371 bytes --]
On Wed, 2015-11-18 at 10:46 +0100, Robert Baldyga wrote:
> Hi Wei,
>
> On 11/18/2015 07:13 AM, Wei, Jiangang wrote:
> > To whom it may concernï¼
> >
> > Sorry to bother again,
> > But any comment about this patchï¼
> >
>
> Reviewed-by: Robert Baldyga <r.baldyga@samsung.com>
>
> It looks good to me. By the way, maybe we should also close file
> descriptors in error path?
Thanks for your kindness and comments,
I update it and send the v2.
If you have any other advice, Please let me know.
Thanks,
wei
>
> Thanks,
> Robert Baldyga
>
> > On Mon, 2015-11-09 at 14:16 +0800, Wei Jiangang wrote:
> >> Free buffer to avoid memory leak upon failure occurs.
> >>
> >> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
> >> ---
> >> tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c | 4 ++++
> >> tools/usb/ffs-aio-example/simple/device_app/aio_simple.c | 4 ++++
> >> 2 files changed, 8 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..3eb1a92baacf 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,24 @@ 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) {
> >> + free(ep_path);
> >> perror("unable do write descriptors");
> >> return 1;
> >> }
> >> if (write(ep0, &strings, sizeof(strings)) < 0) {
> >> + 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..ac96892ca5d2 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,17 @@ 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) {
> >> + free(ep_path);
> >> perror("unable do write descriptors");
> >> return 1;
> >> }
> >> if (write(ep0, &strings, sizeof(strings)) < 0) {
> >> + free(ep_path);
> >> perror("unable to write strings");
> >> return 1;
> >> }
> >> @@ -249,6 +252,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;
> >
>
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-11-19 9:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 6:16 [PATCH] tools: ffs-aio-example: free memory upon failure Wei Jiangang
2015-11-18 6:13 ` Wei, Jiangang
2015-11-18 9:46 ` Robert Baldyga
2015-11-19 9:26 ` [PATCH v2] tools: ffs-aio-example: clean up " Wei Jiangang
2015-11-19 9:30 ` [PATCH] tools: ffs-aio-example: free memory " Wei, Jiangang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.