mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free. Klocwork #306 (at least the first part, checking malloc)
This commit is contained in:
		
							parent
							
								
									0f7dbf731a
								
							
						
					
					
						commit
						ebcf8759bb
					
				
					 1 changed files with 13 additions and 4 deletions
				
			
		| 
						 | 
					@ -410,6 +410,11 @@ longimagedata(PyObject *self, PyObject *args)
 | 
				
			||||||
		addlongimgtag(base, xsize, ysize);
 | 
							addlongimgtag(base, xsize, ysize);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		verdat = (unsigned char *)malloc(xsize);
 | 
							verdat = (unsigned char *)malloc(xsize);
 | 
				
			||||||
 | 
							if (!verdat) {
 | 
				
			||||||
 | 
								Py_CLEAR(rv);
 | 
				
			||||||
 | 
								goto finally;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fseek(inf, 512, SEEK_SET);
 | 
							fseek(inf, 512, SEEK_SET);
 | 
				
			||||||
		for (z = 0; z < zsize; z++) {
 | 
							for (z = 0; z < zsize; z++) {
 | 
				
			||||||
			lptr = base;
 | 
								lptr = base;
 | 
				
			||||||
| 
						 | 
					@ -431,10 +436,14 @@ longimagedata(PyObject *self, PyObject *args)
 | 
				
			||||||
			copybw((Py_Int32 *) base, xsize * ysize);
 | 
								copybw((Py_Int32 *) base, xsize * ysize);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
  finally:
 | 
					  finally:
 | 
				
			||||||
	free(starttab);
 | 
						if (starttab)
 | 
				
			||||||
	free(lengthtab);
 | 
							free(starttab);
 | 
				
			||||||
	free(rledat);
 | 
						if (lengthtab)
 | 
				
			||||||
	free(verdat);
 | 
							free(lengthtab);
 | 
				
			||||||
 | 
						if (rledat)
 | 
				
			||||||
 | 
							free(rledat);
 | 
				
			||||||
 | 
						if (verdat)
 | 
				
			||||||
 | 
							free(verdat);
 | 
				
			||||||
	fclose(inf);
 | 
						fclose(inf);
 | 
				
			||||||
	return rv;
 | 
						return rv;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue