diff mbox

[U-Boot,2/6,v2] LZMA: Avoid free on null pointer

Message ID 1291469358-25023-3-git-send-email-luigi.mantellini@idf-hit.com
State Changes Requested
Headers show

Commit Message

luigi.mantellini@idf-hit.com Dec. 4, 2010, 1:29 p.m. UTC
Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
---
 lib/lzma/LzmaDec.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Comments

Wolfgang Denk Dec. 4, 2010, 10:24 p.m. UTC | #1
Dear Luigi 'Comio' Mantellini,

In message <1291469358-25023-3-git-send-email-luigi.mantellini@idf-hit.com> you wrote:
> 
> Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
> ---
>  lib/lzma/LzmaDec.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c
> index f941da2..b2a3aec 100644
> --- a/lib/lzma/LzmaDec.c
> +++ b/lib/lzma/LzmaDec.c
> @@ -913,7 +913,9 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
>  
>  void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
>  {
> -  alloc->Free(alloc, p->probs);
> +  if (p->probs) {
> +    alloc->Free(alloc, p->probs);
> +  }
>    p->probs = 0;
>  }

Incorrect indentation, and no braces needed for single line
statements.

Best regards,

Wolfgang Denk
Joakim Tjernlund Dec. 5, 2010, 12:45 a.m. UTC | #2
>
> Dear Luigi 'Comio' Mantellini,
>
> In message <1291469358-25023-3-git-send-email-luigi.mantellini@idf-hit.com> you wrote:
> >
> > Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
> > ---
> >  lib/lzma/LzmaDec.c |    4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> >
> > diff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c
> > index f941da2..b2a3aec 100644
> > --- a/lib/lzma/LzmaDec.c
> > +++ b/lib/lzma/LzmaDec.c
> > @@ -913,7 +913,9 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
> >
> >  void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
> >  {
> > -  alloc->Free(alloc, p->probs);
> > +  if (p->probs) {
> > +    alloc->Free(alloc, p->probs);
> > +  }
> >    p->probs = 0;
> >  }
>
> Incorrect indentation, and no braces needed for single line
> statements.

.. and that NULL test belongs in alloc->Free like the standard free() does.
diff mbox

Patch

diff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c
index f941da2..b2a3aec 100644
--- a/lib/lzma/LzmaDec.c
+++ b/lib/lzma/LzmaDec.c
@@ -913,7 +913,9 @@  SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
 
 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
 {
-  alloc->Free(alloc, p->probs);
+  if (p->probs) {
+    alloc->Free(alloc, p->probs);
+  }
   p->probs = 0;
 }