Fix GstAmcSurfaceTexture segfault

Check that `self` and `self->callback` are defined. `self` can be set to
`NULL` in `remove_listener`, and `self->callback` can be set to `NULL`
inside `gst_amc_surface_texture_jni_set_on_frame_available_callback`.
This can cause a segfault since the Java object can outlive the C
object, and call the callback after `remove_listener` is called.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3056>
This commit is contained in:
Andrew Pritchard 2022-03-25 14:25:02 +11:00 committed by Tim-Philipp Müller
parent 2a4f96861e
commit b91c2c1c65

View file

@ -243,6 +243,8 @@ on_frame_available_cb (JNIEnv * env, jobject thiz,
long long context, jobject surfaceTexture)
{
GstAmcSurfaceTextureJNI *self = JLONG_TO_GPOINTER (context);
if (!self || !self->callback)
return;
self->callback (GST_AMC_SURFACE_TEXTURE (self), self->user_data);
}