evbuffer_add_file: fix freeing of segment in the error path

if evbuffer_add_file_segment() fails it returns -1, so we should call
evbuffer_file_segment_free() only on error, and this -1 not 0.

Fixes: 6a81b1f5 ("Avoid double-free on error in evbuffer_add_file. Found by coverity.")
Backport-to: 2.1
This commit is contained in:
Azat Khuzhin 2019-09-21 23:30:48 +03:00
parent 148d12ad31
commit 4727150a54
No known key found for this signature in database
GPG Key ID: B86086848EF8686D

View File

@ -3316,7 +3316,7 @@ evbuffer_add_file(struct evbuffer *buf, int fd, ev_off_t offset, ev_off_t length
if (!seg)
return -1;
r = evbuffer_add_file_segment(buf, seg, 0, length);
if (r == 0)
if (r == -1)
evbuffer_file_segment_free(seg);
return r;
}