Fix buffer leaking on connection disconnect

This commit is contained in:
Kamil Trzcinski
2022-04-06 14:27:35 +02:00
parent aad601d575
commit 899204916f
5 changed files with 13 additions and 5 deletions

View File

@ -64,11 +64,12 @@ error:
void http_stream(http_worker_t *worker, FILE *stream)
{
int counter = 0;
buffer_t *buf = NULL;
fprintf(stream, STREAM_HEADER);
buffer_lock_use(&http_jpeg, 1);
while (!feof(stream)) {
buffer_t *buf = buffer_lock_get(&http_jpeg, 0, &counter);
buf = buffer_lock_get(&http_jpeg, 0, &counter);
if (!buf) {
fprintf(stream, STREAM_ERROR, -1, "No frames.");
@ -86,8 +87,10 @@ void http_stream(http_worker_t *worker, FILE *stream)
}
buffer_consumed(buf, "jpeg-stream");
buf = NULL;
}
error:
buffer_consumed(buf, "error");
buffer_lock_use(&http_jpeg, -1);
}