Do not call fclose() on a NULL pointer
The if clause is true if cache is NULL. man 3 fclose says: The behaviour of fclose() is undefined if the stream parameter is an illegal pointer, or is a descriptor already passed to a previous invo‐ cation of fclose(). Check if cache is NULL before calling fclose().
This commit is contained in:
		
							
								
								
									
										3
									
								
								buffer.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								buffer.c
									
									
									
									
									
								
							| @@ -707,7 +707,8 @@ readBufferCache(Buffer *buf) | |||||||
|  |  | ||||||
|     cache = fopen(buf->savecache, "r"); |     cache = fopen(buf->savecache, "r"); | ||||||
|     if (cache == NULL || fread1(clnum, cache) || fread1(tlnum, cache)) { |     if (cache == NULL || fread1(clnum, cache) || fread1(tlnum, cache)) { | ||||||
| 	fclose(cache); | 	if (cache != NULL) | ||||||
|  | 	    fclose(cache); | ||||||
| 	buf->savecache = NULL; | 	buf->savecache = NULL; | ||||||
| 	return -1; | 	return -1; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user