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
(cherry picked from commit 4727150a54e21725f0ef4f43ca5028cc6f353664)
This commit is contained in:
Azat Khuzhin 2019-09-21 23:30:48 +03:00
parent f4a6152c3b
commit 5f017bde64

View File

@ -3299,7 +3299,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;
}