[U-Boot] [PATCH] LZMA: Avoid free on null pointer.

Luigi 'Comio' Mantellini luigi.mantellini at idf-hit.com
Sun Dec 5 10:18:44 CET 2010


On structure Initialization, LZMA code tries to free the dictionary
and probs buffers, also when these are null pointers. Add some
check in order to prevent the free on null pointers.

Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantellini at idf-hit.com>
---
 lib/lzma/LzmaDec.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c
index f941da2..e2dab44 100644
--- a/lib/lzma/LzmaDec.c
+++ b/lib/lzma/LzmaDec.c
@@ -960,7 +960,8 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
   UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
   if (p->probs == 0 || numProbs != p->numProbs)
   {
-    LzmaDec_FreeProbs(p, alloc);
+    if (p->probs)
+      LzmaDec_FreeProbs(p, alloc);
     p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
     p->numProbs = numProbs;
     if (p->probs == 0)
@@ -987,7 +988,8 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
   dicBufSize = propNew.dicSize;
   if (p->dic == 0 || dicBufSize != p->dicBufSize)
   {
-    LzmaDec_FreeDict(p, alloc);
+    if (p->dic)
+      LzmaDec_FreeDict(p, alloc);
     p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
     if (p->dic == 0)
     {
-- 
1.7.2.3



More information about the U-Boot mailing list