Fix buffer leaking on connection disconnect
This commit is contained in:
		| @@ -5,4 +5,4 @@ cd "$SCRIPT_DIR" | ||||
|  | ||||
| set -xeo pipefail | ||||
| make | ||||
| ./camera_stream -camera-path=$(echo /dev/v4l/by-path/*.csi-video-index0) "$@" | ||||
| $GDB ./camera_stream -camera-path=$(echo /dev/v4l/by-path/*.csi-video-index0) "$@" | ||||
|   | ||||
| @@ -30,12 +30,13 @@ void http_video(http_worker_t *worker, FILE *stream) | ||||
|   bool had_key_frame = false; | ||||
|   bool requested_key_frame = false; | ||||
|   int counter = 0; | ||||
|   buffer_t *buf = NULL; | ||||
|   fprintf(stream, VIDEO_HEADER); | ||||
|  | ||||
|   buffer_lock_use(&http_h264, 1); | ||||
|  | ||||
|   while (!feof(stream)) { | ||||
|     buffer_t *buf = buffer_lock_get(&http_h264, 0, &counter); | ||||
|     buf = buffer_lock_get(&http_h264, 0, &counter); | ||||
|     if (!buf) { | ||||
|       goto error; | ||||
|     } | ||||
| @@ -59,8 +60,10 @@ void http_video(http_worker_t *worker, FILE *stream) | ||||
|       requested_key_frame = true; | ||||
|     } | ||||
|     buffer_consumed(buf, "h264-stream"); | ||||
|     buf = NULL; | ||||
|   } | ||||
|  | ||||
| error: | ||||
|   buffer_consumed(buf, "error"); | ||||
|   buffer_lock_use(&http_h264, -1); | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
| } | ||||
|   | ||||
| @@ -65,9 +65,11 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis | ||||
|       source->device->output_device->paused = paused; | ||||
|     } | ||||
|  | ||||
|     int count_enqueued = buffer_list_count_enqueued(source); | ||||
|  | ||||
|     fds[n].fd = source->device->fd; | ||||
|     fds[n].events = POLLHUP; | ||||
|     if (!source->device->paused) | ||||
|     if (!source->device->paused && count_enqueued > 0) | ||||
|       fds[n].events |= POLLIN; | ||||
|     fds[n].revents = 0; | ||||
|     buf_lists[n] = source; | ||||
|   | ||||
| @@ -5,4 +5,4 @@ cd "$SCRIPT_DIR" | ||||
|  | ||||
| set -xeo pipefail | ||||
| make | ||||
| ./camera_stream -camera-path=$(echo /dev/v4l/by-id/usb-*-video-index0 ) "$@" | ||||
| $GDB ./camera_stream -camera-path=$(echo /dev/v4l/by-id/usb-*-video-index0 ) "$@" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kamil Trzcinski
					Kamil Trzcinski