Bug 497363. qcms: Fix a memory leak when fread() fails. r=joedrew
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 12 Jun 2009 14:38:34 -0400
changeset 29151 18c9c79509c129dff805ab61ac069c15fd218651
parent 29150 b07348ce9233912fdb7f143150320cd066edbbc1
child 29152 d616a84cad243e13f14e0971809be353731ed122
push id7446
push userjmuizelaar@mozilla.com
push dateFri, 12 Jun 2009 18:40:44 +0000
treeherdermozilla-central@18c9c79509c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoedrew
bugs497363
milestone1.9.2a1pre
Bug 497363. qcms: Fix a memory leak when fread() fails. r=joedrew Fixes a possible leak in qcms_profile_from_file() when fread() can't read the entire profile.
gfx/qcms/iccread.c
--- a/gfx/qcms/iccread.c
+++ b/gfx/qcms/iccread.c
@@ -760,18 +760,20 @@ qcms_profile* qcms_profile_from_file(FIL
 		return NO_MEM_PROFILE;
 
 	/* copy in length to the front so that the buffer will contain the entire profile */
 	*((__be32*)data) = length_be;
 	remaining_length = length - sizeof(length_be);
 
 	/* read the rest profile */
 	read_length = fread((unsigned char*)data + sizeof(length_be), 1, remaining_length, file);
-	if (read_length != remaining_length)
+	if (read_length != remaining_length) {
+		free(data);
 		return INVALID_PROFILE;
+	}
 
 	profile = qcms_profile_from_memory(data, length);
 	free(data);
 	return profile;
 }
 
 qcms_profile* qcms_profile_from_path(const char *path)
 {