Draft
Conversation
On #xmm2 Chewi reported c++/tut7 to be broken at start:
```
GLib-WARNING **: glib-2.56.2/glib/giounix.c:410
Error while getting flags for FD: Bad file descriptor (9)
```
valgrind shows the problem as read of uninitialized data:
```
$ valgrind ./tut7
==32268== Conditional jump or move depends on uninitialised value(s)
==32268== at 0x49DC36B: xmmsc_mainloop_gmain_init (xmmsclient-glib.c:80)
==32268== by 0x49E11BE: Xmms::GMainloop::GMainloop(xmmsc_connection_St*) (xmmsclient++-glib.cpp:11)
==32268== by 0x10C64D: main (in /home/slyfox/dev/git/xmms2-devel/doc/tutorial/c++/tut7)
==32268== Uninitialised value was created by a stack allocation
==32268== at 0x49E119A: Xmms::GMainloop::GMainloop(xmmsc_connection_St*) (xmmsclient++-glib.cpp:8)
```
This happens due to use of dangling C++ reference to stack variable:
```
// somewhere in src/include/xmmsclient/xmmsclient++/mainloop.h
class MainloopInterface {
MainloopInterface( xmmsc_connection_t* conn ) :
running_( false ), conn_( conn ) { }
protected:
bool running_;
xmmsc_connection_t*& conn_;
}
```
Note: `conn_` refers to dangling local variable of
`MainloopInterface::MainloopInterface` constructor.
The fix is to pass through pointer reference.
`MainLoop::MainLoop()` already does it.
Reported-by: James Le Cuirot
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Contributor
|
I'm actually a little too tired to think right now but at least |
gentoo-bot
pushed a commit
to gentoo/gentoo
that referenced
this pull request
Dec 6, 2018
Picked patch from xmms2/xmms2-devel#5 Reported-by: James Le Cuirot Package-Manager: Portage-2.3.52, Repoman-2.3.12 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Contributor
Author
|
Good catch! That |
Contributor
Author
|
Converting to draft as I think it introduces dangling reference to a temporary on initial object creation. I'll spend some time tracing through lifetimes more explicitly and redo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On #xmm2 Chewi reported c++/tut7 to be broken at start:
valgrind shows the problem as read of uninitialized data:
This happens due to use of dangling C++ reference to stack variable:
Note:
conn_refers to dangling local variable ofMainloopInterface::MainloopInterfaceconstructor.The fix is to pass through pointer reference.
MainLoop::MainLoop()already does it.Reported-by: James Le Cuirot
Signed-off-by: Sergei Trofimovich slyfox@gentoo.org