Skip to content
  • Stefan Beller's avatar
    parse_object_buffer: correct freeing the buffer · 8e92e8f2
    Stefan Beller authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    If we exit early in the function parse_object_buffer, we did not
    write to *eaten_p. Then the calling function parse_object, which looks
    like the following with respect to the eaten variable, cannot rely on a
    proper value set in eaten, hence the freeing of the buffer depends
    on random values in memory.
    
    	struct object *parse_object(const unsigned char *sha1)
    	{
    		int eaten;
    		...
    		obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
    		if (!eaten)
    			free(buffer);
    	}
    
    This change makes sure, the buffer freeing condition is deterministic.
    
    Signed-off-by: default avatarStefan Beller <stefanbeller@googlemail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    8e92e8f2