[NBS] Add validation of instance to prevent crash 57/247857/1
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 5 Nov 2020 11:20:21 +0000 (12:20 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Tue, 17 Nov 2020 13:03:59 +0000 (13:03 +0000)
commit2a877c12b9031ed302f91f919ab0cd93b1c10ce7
tree8bcdf08836168c7716d97c85770fe6f00a7a379e
parentc35e5a45dcc957242fff05d3f4c9d64823e4ff61
[NBS] Add validation of instance to prevent crash

[Bug] In case of destroying instance before the operation:
* requestRouteToHost
* releaseRouteToHost
is finished, invalidated instance was used in code.

[Reproduction] In my case it was execution of below code max 10 times:
function crashApplicationWithNBS() {
    try {
        tizen.networkbearerselection.releaseRouteToHost(
            "CELLULAR", "www.onet.pl", addRouteAndReload, addRouteAndReload);
    } catch (e) {
        addRouteAndReload();
    }
}

function addRouteAndReload() {
    var statuscb =
    {
        onsuccess: function () {
            console.log("onsuccess func is called");
        },
        ondisconnected: function () {
            console.log("ondisconnected func is called");
        }
    };
    function ecb(e) {
        console.log("error callback is called: " + e.message + ": " + e.code);
    }
    setTimeout(() => {
        try {
            tizen.networkbearerselection.requestRouteToHost(
                "CELLULAR", "www.onet.pl", statuscb, ecb)
        } catch (e) { console.log(e) }
    }, 500);
    setTimeout(() => { location.href = "index.html"; }, 490);
}

[Verification]
* Crash does not occur. Crash situation is only signalled
with log:
DoAndPostMessage(264) > Trying to post message to non-existing instance: [0xb8cb1730], ignoring
* Success and error callbacks are properly triggered

Change-Id: I6adac13a8a99dbc114102bbd2ffced6bf012cfce
src/common/extension.cc
src/common/extension.h
src/networkbearerselection/networkbearerselection_instance.cc