[01/16] Fix memory leak with broken bitmap files in XReadBitmapFileData

Submitted by Ander Conselvan de Oliveira on March 30, 2011, 8:11 p.m.

Details

Message ID 1301490729-22084-2-git-send-email-ander.conselvan-de-oliveira@nokia.com
State Accepted, archived
Commit 1a944260182bb552b954d69f6355c2760d4415df
Headers show

Not browsing as part of any series.

Commit Message

Ander Conselvan de Oliveira March 30, 2011, 8:11 p.m.
Bitmap file data is read looping through the lines in the input file. If
there is extra data after the bitmap, these lines will be processed and
if this data represents another bitmap it will replace the one read
before causing the memory allocated for bits to leak.

This changes the code to stop processing the file once a bitmap was
read.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira@nokia.com>
---
 src/RdBitF.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/RdBitF.c b/src/RdBitF.c
index 07967ae..ab7d800 100644
--- a/src/RdBitF.c
+++ b/src/RdBitF.c
@@ -216,6 +216,11 @@  XReadBitmapFileData (
 		*ptr=value;
 	    }
 	}
+
+	/* If we got to this point, we read a full bitmap file. Break so we don't
+	 * start reading another one from the same file and leak the memory
+	 * allocated for the previous one. */
+	break;
     }					/* end while */
 
     fclose(fstream);