* [PATCH] convert-dtsv0-lexer.l: fix memory leak
@ 2016-07-12 22:35 Jean-Christophe Dubois
[not found] ` <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jean-Christophe Dubois @ 2016-07-12 22:35 UTC (permalink / raw)
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA,
david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+,
jdl-CYoMK+44s/E
Cc: Jean-Christophe Dubois
CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_storage: Variable newname going out of scope leaks the storage it points to
Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
---
convert-dtsv0-lexer.l | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
index 259e527..8d8289b 100644
--- a/convert-dtsv0-lexer.l
+++ b/convert-dtsv0-lexer.l
@@ -208,6 +208,12 @@ static void convert_file(const char *fname)
char *newname;
newname = xmalloc(len + sizeof(suffix));
+
+ if (!newname) {
+ die("failed to allocate memory for input file %s: %s\n",
+ fname, strerror(errno));
+ }
+
memcpy(newname, fname, len);
memcpy(newname + len, suffix, sizeof(suffix));
@@ -223,6 +229,8 @@ static void convert_file(const char *fname)
while(yylex())
;
+
+ free(newname);
}
int main(int argc, char *argv[])
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] convert-dtsv0-lexer.l: fix memory leak
[not found] ` <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
@ 2016-07-13 2:04 ` David Gibson
[not found] ` <20160713020446.GC14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: David Gibson @ 2016-07-13 2:04 UTC (permalink / raw)
To: Jean-Christophe Dubois
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, jdl-CYoMK+44s/E
[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]
On Wed, Jul 13, 2016 at 12:35:50AM +0200, Jean-Christophe Dubois wrote:
> CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
> 9. leaked_storage: Variable newname going out of scope leaks the storage it points to
>
> Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
> ---
> convert-dtsv0-lexer.l | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
> index 259e527..8d8289b 100644
> --- a/convert-dtsv0-lexer.l
> +++ b/convert-dtsv0-lexer.l
> @@ -208,6 +208,12 @@ static void convert_file(const char *fname)
> char *newname;
>
> newname = xmalloc(len + sizeof(suffix));
> +
> + if (!newname) {
> + die("failed to allocate memory for input file %s: %s\n",
> + fname, strerror(errno));
> + }
> +
This hunk is unnecessary. xmalloc() already die()s rather than failing.
> memcpy(newname, fname, len);
> memcpy(newname + len, suffix, sizeof(suffix));
>
> @@ -223,6 +229,8 @@ static void convert_file(const char *fname)
>
> while(yylex())
> ;
> +
> + free(newname);
> }
>
> int main(int argc, char *argv[])
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] convert-dtsv0-lexer.l: fix memory leak
[not found] ` <20160713020446.GC14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
@ 2016-07-13 6:02 ` Jean-Christophe DUBOIS
[not found] ` <5785D973.7090108-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jean-Christophe DUBOIS @ 2016-07-13 6:02 UTC (permalink / raw)
To: David Gibson; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, jdl-CYoMK+44s/E
Le 13/07/2016 04:04, David Gibson a écrit :
> On Wed, Jul 13, 2016 at 12:35:50AM +0200, Jean-Christophe Dubois wrote:
>> CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
>> 9. leaked_storage: Variable newname going out of scope leaks the storage it points to
>>
>> Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
>> ---
>> convert-dtsv0-lexer.l | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
>> index 259e527..8d8289b 100644
>> --- a/convert-dtsv0-lexer.l
>> +++ b/convert-dtsv0-lexer.l
>> @@ -208,6 +208,12 @@ static void convert_file(const char *fname)
>> char *newname;
>>
>> newname = xmalloc(len + sizeof(suffix));
>> +
>> + if (!newname) {
>> + die("failed to allocate memory for input file %s: %s\n",
>> + fname, strerror(errno));
>> + }
>> +
> This hunk is unnecessary. xmalloc() already die()s rather than failing.
OK.
On a correctness point of view there is still the "free" to be done (see
below).
>
>> memcpy(newname, fname, len);
>> memcpy(newname + len, suffix, sizeof(suffix));
>>
>> @@ -223,6 +229,8 @@ static void convert_file(const char *fname)
>>
>> while(yylex())
>> ;
>> +
>> + free(newname);
>> }
>>
>> int main(int argc, char *argv[])
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] convert-dtsv0-lexer.l: fix memory leak
[not found] ` <5785D973.7090108-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
@ 2016-07-23 14:51 ` David Gibson
0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2016-07-23 14:51 UTC (permalink / raw)
To: Jean-Christophe DUBOIS
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, jdl-CYoMK+44s/E
[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]
On Wed, Jul 13, 2016 at 08:02:27AM +0200, Jean-Christophe DUBOIS wrote:
> Le 13/07/2016 04:04, David Gibson a écrit :
> > On Wed, Jul 13, 2016 at 12:35:50AM +0200, Jean-Christophe Dubois wrote:
> > > CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
> > > 9. leaked_storage: Variable newname going out of scope leaks the storage it points to
> > >
> > > Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
> > > ---
> > > convert-dtsv0-lexer.l | 8 ++++++++
> > > 1 file changed, 8 insertions(+)
> > >
> > > diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
> > > index 259e527..8d8289b 100644
> > > --- a/convert-dtsv0-lexer.l
> > > +++ b/convert-dtsv0-lexer.l
> > > @@ -208,6 +208,12 @@ static void convert_file(const char *fname)
> > > char *newname;
> > > newname = xmalloc(len + sizeof(suffix));
> > > +
> > > + if (!newname) {
> > > + die("failed to allocate memory for input file %s: %s\n",
> > > + fname, strerror(errno));
> > > + }
> > > +
> > This hunk is unnecessary. xmalloc() already die()s rather than failing.
> OK.
>
> On a correctness point of view there is still the "free" to be done (see
> below).
Yes. That was a suggestion to respin. Never mind now though, I've
removed the unnecessary hunk and applied.
> >
> > > memcpy(newname, fname, len);
> > > memcpy(newname + len, suffix, sizeof(suffix));
> > > @@ -223,6 +229,8 @@ static void convert_file(const char *fname)
> > > while(yylex())
> > > ;
> > > +
> > > + free(newname);
> > > }
> > > int main(int argc, char *argv[])
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-07-23 14:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 22:35 [PATCH] convert-dtsv0-lexer.l: fix memory leak Jean-Christophe Dubois
[not found] ` <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
2016-07-13 2:04 ` David Gibson
[not found] ` <20160713020446.GC14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-13 6:02 ` Jean-Christophe DUBOIS
[not found] ` <5785D973.7090108-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
2016-07-23 14:51 ` David Gibson
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.