]> git.tdb.fi Git - libs/gui.git/commitdiff
Don't leak memory if JsDevice constructor throws
authorMikko Rasa <tdb@tdb.fi>
Sat, 23 Jul 2016 15:50:32 +0000 (18:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 23 Jul 2016 15:50:32 +0000 (18:50 +0300)
source/input/linux/gamecontroller.cpp

index 8a4e8d43c2dbb3f06c9af66dd347dad721281f46..2fc624e7b83db87e677c0c2bbe5fdda0fb0ccd53 100644 (file)
@@ -12,10 +12,12 @@ namespace Msp {
 namespace Input {
 
 GameController::GameController(unsigned index):
-       priv(new Private),
        event_disp(0)
 {
-       priv->dev = new JsDevice(format("/dev/input/js%d", index));
+       JsDevice *device = new JsDevice(format("/dev/input/js%d", index));
+
+       priv = new Private;
+       priv->dev = device;
        priv->dev->signal_data_available.connect(sigc::mem_fun(this, static_cast<void (GameController::*)()>(&GameController::tick)));
        name = priv->dev->get_name();
        tick(Time::zero);