Riverside-Software / sonar-openedge

CABL (Code Analyzer for ABL in SonarQube) - ABL ANTLR4 Parser
https://riverside-software.fr
GNU Lesser General Public License v3.0
63 stars 26 forks source link

MEMPTR memory leak - false positives #1125

Closed Ton-Pe closed 4 weeks ago

Ton-Pe commented 6 months ago

Case 1:

Following code gives a false positive. Size of memptr is set inside the block and then released outside that block.

DEFINE VARIABLE mReceiveData AS MEMPTR   NO-UNDO.

IF TRUE THEN DO:
    SET-SIZE(mReceiveData) = 100.
END.

SET-SIZE(mReceiveData) = 0.

If release is done inside the same block or moved to finally-block, then issue is not raised.

Case 2:

Following code where copy-lob is done inside a nested block, gives false positive.

DEFINE VARIABLE mReceiveData AS MEMPTR   NO-UNDO.
DEFINE VARIABLE mSendData    AS MEMPTR   NO-UNDO.

IF TRUE THEN DO: // First level
    DO: // second level
        COPY-LOB mReceiveData TO mSendData.
    END.
END.

FINALLY:
    SET-SIZE (mSendData) = 0.
END FINALLY.

For a comparison, this code, where there is only one block, issue is not raised:

DEFINE VARIABLE mReceiveData AS MEMPTR   NO-UNDO.
DEFINE VARIABLE mSendData    AS MEMPTR   NO-UNDO.

IF TRUE THEN DO:
        COPY-LOB mReceiveData TO mSendData.
END.

FINALLY:
    SET-SIZE (mSendData) = 0.
END FINALLY.

This is similar to issue #1121 in DynamicObjectLeak rule

Philippe-La commented 2 months ago

Case 1:

Following code gives a false positive. Size of memptr is set inside the block and then released outside that block.

DEFINE VARIABLE mReceiveData AS MEMPTR   NO-UNDO.

IF TRUE THEN DO:
    SET-SIZE(mReceiveData) = 100.
END.

SET-SIZE(mReceiveData) = 0.

If release is done inside the same block or moved to finally-block, then issue is not raised.

+1

gquerret commented 4 weeks ago

Fixed in develop branch, will be included in next release