damage: Increment/decrement reference count before/after check

This is prudent. The user might throw away these buffers before the
damage check finishes.
pull/22/head
Andri Yngvason 2020-01-29 21:33:13 +00:00
parent c29e747ecf
commit 61efca48f0
2 changed files with 15 additions and 8 deletions

View File

@ -91,6 +91,6 @@ int nvnc_feed_frame(struct nvnc* self, struct nvnc_fb* fb,
* *
* This is a utility function that may be used to reduce network traffic. * This is a utility function that may be used to reduce network traffic.
*/ */
int nvnc_check_damage(const struct nvnc_fb* fb0, const struct nvnc_fb* fb1, int nvnc_check_damage(struct nvnc_fb* fb0, struct nvnc_fb* fb1,
int x_hint, int y_hint, int width_hint, int height_hint, int x_hint, int y_hint, int width_hint, int height_hint,
nvnc_damage_fn on_check_done, void* userdata); nvnc_damage_fn on_check_done, void* userdata);

View File

@ -16,8 +16,8 @@
struct damage_check { struct damage_check {
uv_work_t work; uv_work_t work;
const struct nvnc_fb* fb0; struct nvnc_fb* fb0;
const struct nvnc_fb* fb1; struct nvnc_fb* fb1;
int x_hint; int x_hint;
int y_hint; int y_hint;
int width_hint; int width_hint;
@ -103,13 +103,16 @@ void on_damage_check_done_linear(uv_work_t* work, int status)
check->on_done(&check->damage, check->userdata); check->on_done(&check->damage, check->userdata);
nvnc_fb_unref(check->fb1);
nvnc_fb_unref(check->fb0);
pixman_region_fini(&check->damage); pixman_region_fini(&check->damage);
free(check); free(check);
} }
int check_damage_linear_threaded(const struct nvnc_fb* fb0, int check_damage_linear_threaded(struct nvnc_fb* fb0, struct nvnc_fb* fb1,
const struct nvnc_fb* fb1, int x_hint, int x_hint, int y_hint,
int y_hint, int width_hint, int height_hint, int width_hint, int height_hint,
nvnc_damage_fn on_check_done, void* userdata) nvnc_damage_fn on_check_done, void* userdata)
{ {
struct damage_check* work = calloc(1, sizeof(*work)); struct damage_check* work = calloc(1, sizeof(*work));
@ -130,14 +133,18 @@ int check_damage_linear_threaded(const struct nvnc_fb* fb0,
int rc = uv_queue_work(uv_default_loop(), &work->work, int rc = uv_queue_work(uv_default_loop(), &work->work,
do_damage_check_linear, do_damage_check_linear,
on_damage_check_done_linear); on_damage_check_done_linear);
if (rc < 0) if (rc >= 0) {
nvnc_fb_ref(fb0);
nvnc_fb_ref(fb1);
} else {
free(work); free(work);
}
return rc; return rc;
} }
EXPORT EXPORT
int nvnc_check_damage(const struct nvnc_fb* fb0, const struct nvnc_fb* fb1, int nvnc_check_damage(struct nvnc_fb* fb0, struct nvnc_fb* fb1,
int x_hint, int y_hint, int width_hint, int height_hint, int x_hint, int y_hint, int width_hint, int height_hint,
nvnc_damage_fn on_check_done, void* userdata) nvnc_damage_fn on_check_done, void* userdata)
{ {