After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 765418 - gst_buffer_unmap() should reset GstMapInfo state
gst_buffer_unmap() should reset GstMapInfo state
Status: RESOLVED WONTFIX
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-22 09:17 UTC by Marcin Kolny (IRC: loganek)
Modified: 2016-04-23 15:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-buffer-reset-GstMapInfo-state-in-gst_buffer_unmap.patch (1014 bytes, patch)
2016-04-22 09:18 UTC, Marcin Kolny (IRC: loganek)
reviewed Details | Review

Description Marcin Kolny (IRC: loganek) 2016-04-22 09:17:23 UTC
It's very minor thing. I think, that when user calls gst_buffer_unmap (), he should no longer be able to use GstMapInfo object, since using this object after mapping might lead to unexpected behavior (e.g. memory can be removed).
However, GstMapInfo object is really needed after unmapping, user can always make a copy of this object.
Comment 1 Marcin Kolny (IRC: loganek) 2016-04-22 09:18:08 UTC
Created attachment 326534 [details] [review]
0001-buffer-reset-GstMapInfo-state-in-gst_buffer_unmap.patch
Comment 2 Sebastian Dröge (slomo) 2016-04-22 09:30:35 UTC
Comment on attachment 326534 [details] [review]
0001-buffer-reset-GstMapInfo-state-in-gst_buffer_unmap.patch

While this makes sense, I wouldn't be surprised if there is code out there using map.size after unmap... which would now fail even if that's arguably invalid.

This needs some serious testing to understand the impact.
Comment 3 Marcin Kolny (IRC: loganek) 2016-04-22 10:02:17 UTC
When I first time saw the unmap() method, I was pretty sure that GstMapInfo is reset to initial state - this behavior seems to be natural for me. Moreover, I think it's better to explicitly copy some values before unmap (e.g. size) if the value is needed afterwards, instead of letting user to accidentally use invalid object.
Comment 4 Tim-Philipp Müller 2016-04-22 10:16:47 UTC
I wonder if we've tried this before but had to revert it.

I don't think we can change this now, even if I agree that it'd been cleaner to do so.

GstMapInfo is a stack-allocated helper struct, I don't think there's any reason to believe it's in any particular state after unmapping. Arguably it's also desirable from a performance point of view not to clear it unnecessarily.
Comment 5 Sebastian Dröge (slomo) 2016-04-22 10:19:59 UTC
It's basically in the same state as the memory behind a pointer after free(). Nobody knows ;)

I think it would nonetheless be beneficial to check if and where we use something from the map info after unmap, and fix those cases.
Comment 6 Tim-Philipp Müller 2016-04-23 12:50:47 UTC
Sounds a very tedious thing to check without compiler help (like marking a stack-variable as 'warn if accessed again after here without assignment'), are you planning on doing that?

I think this is WONTFIX otherwise :)
Comment 7 Marcin Kolny (IRC: loganek) 2016-04-23 13:03:25 UTC
No, it's a bit time consuming, and I don't expect to find enough time for fixing it. Moreover, it doesn't solve my initial problem.
I was thinking about reseting only memory field, but it would be completely inconsistent (why memory, and not the other fields), so I consider it as a stupid idea :)
If GStreamer somewhere access to memory field from GstMapInfo struct, after unmapping, when those memory is already deleted, I think sooner or later someone report this bug.
So for now, I agree with WONTFIX.

Thanks for discussion