-
Notifications
You must be signed in to change notification settings - Fork 426
Fix segfault when accessing FilterContext after Graph object has left scope #2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
This PR might bring regression for a memory leak problem. #1439 |
|
Hmmm. We could keep the weakref and check it's validity every time we cross the libav boundary. Users could still experience weird lifetime problems, but at least those would result in an exception rather than a segfault. Perhaps a "better" solution would be to perform all filter operations on the graph object itself. Something like this: def make_filter(stream: VideoStream) -> Graph:
graph = Graph()
graph.add_buffer(stream, 'my-source')
graph.add('crop', 'crop-to-thumbnail', '100:100')
graph.link_to('my-source', 'crop-to-thumbnail', 0, 0)
graph.add('buffersink', 'my-sink')
graph.link_to('crop-to-thumbnail', 'my-sink', 0, 0)
return graph
filter = make_filter(stream)
filter.push('my-source', frame)I don't think the implementation would have to change too much. |
|
Breaking changes are okay if you think that is the best solution. |
|
Gotcha. If we were to go down the route of introducing breaking changes, would that come with a deprecation period to phase out the old interface? |
|
Yes, it will come with a depreciation period, but that's just out of scope when the new API hasn't been designed yet. |
|
I've written a very basic PoC for my vision of what this tweaked interface should look like. I've not written tests yet, as I want to hear your thoughts before proceeding further. |
|
I think |
|
I'm with you on that, but I can't think of another way we can safely keep the back reference as a weakref without breaking the API. If maintaining API stability is the no. 1 priority then I think we should take the less elegant route of checking weakref validity before crossing the libav boundary. The reference could still get garbage collected, but at least the library wouldn't segfault. |
This reverts commit ec3be49.
Hello. I am experiencing a segfault when performing filter operations due to libav accessing an invalid Graph object. See the following example:
My solution is to remove the weakref entirely, but I'm not sure how much of an impact this has on memory usage. I'm a little in over my head poking around in FFMPEG source, so I'm open to suggestions if this approach isn't feasible.