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

DynamicObjectLeak - False positive #1123

Closed clement-brodu closed 1 month ago

clement-brodu commented 6 months ago

Hello,

Since 2.26.1, it's much better, but I found some false positive :

METHOD PUBLIC VOID Case4 (INPUT pRefresh AS LOGICAL):
        DEFINE VARIABLE vHTT AS HANDLE NO-UNDO.
        DEFINE VARIABLE vHBTT AS HANDLE NO-UNDO.
        DEFINE VARIABLE vHndQuery AS HANDLE NO-UNDO.

        IF pRefresh THEN
        DO:
            // If i remove the 2 lines below, no more error on vHndQuery
            vHBTT = vHTT:DEFAULT-BUFFER-HANDLE.
            vHBTT:BUFFER-CREATE().

            CREATE QUERY vHndQuery. // DynamicObjectLeak issue
        END.

        FINALLY:
            IF VALID-HANDLE(vHndQuery) THEN DELETE OBJECT vHndQuery.
        END FINALLY.
    END METHOD.
    METHOD PUBLIC VOID Case5 ():
        DEFINE VARIABLE vII              AS INTEGER   NO-UNDO.
        DEFINE VARIABLE vNomBuffer       AS CHARACTER NO-UNDO.
        DEFINE VARIABLE vHBuffer         AS HANDLE    NO-UNDO.
        DEFINE VARIABLE vHBufferQuery    AS HANDLE    NO-UNDO.

        BoucleFiltre:
        DO vII = 10 - 1 TO 0 BY -1 ON ERROR UNDO, THROW:

            IF vNomBuffer BEGINS "*" THEN 
            DO:
                // Stuff
            END.
            ELSE IF NOT vNomBuffer BEGINS "*" THEN 
                DO:              
                    CREATE BUFFER vHBufferQuery FOR TABLE vHBuffer BUFFER-NAME vNomBuffer.
                END.   

            FINALLY:
                IF VALID-HANDLE(vHBufferQuery) THEN DELETE OBJECT vHBufferQuery.        
            END FINALLY.           
        END.   
    END METHOD. 
Ton-Pe commented 6 months ago

(moved my comment from #1121 ) I also noticed that if using DELETE WIDGET command instead of DELETE OBJECT. This rule does not recognize these so it gives a false positive.


BLOCK-LEVEL ON ERROR UNDO, THROW.

DEFINE VARIABLE xObj AS HANDLE NO-UNDO.
DEFINE VARIABLE xWid AS HANDLE NO-UNDO.

CREATE BUFFER xObj FOR TABLE "Item" NO-ERROR.
CREATE BUFFER xWid FOR TABLE "Customer" NO-ERROR. /* this line is flagged*/

FINALLY:
IF VALID-HANDLE (xObj) THEN DELETE OBJECT xObj.
IF VALID-HANDLE (xWid) THEN DELETE WIDGET xWid. /* this is not understood as a delete  */
END.

Of course, in this case xWid is not a real widget. Could this be fixed too?

Philippe-La commented 2 months ago

(moved my comment from #1121 ) I also noticed that if using DELETE WIDGET command instead of DELETE OBJECT. This rule does not recognize these so it gives a false positive.


BLOCK-LEVEL ON ERROR UNDO, THROW.

DEFINE VARIABLE xObj AS HANDLE NO-UNDO.
DEFINE VARIABLE xWid AS HANDLE NO-UNDO.

CREATE BUFFER xObj FOR TABLE "Item" NO-ERROR.
CREATE BUFFER xWid FOR TABLE "Customer" NO-ERROR. /* this line is flagged*/

FINALLY:
IF VALID-HANDLE (xObj) THEN DELETE OBJECT xObj.
IF VALID-HANDLE (xWid) THEN DELETE WIDGET xWid. /* this is not understood as a delete  */
END.

Of course, in this case xWid is not a real widget. Could this be fixed too?

+1

gquerret commented 1 month ago

Fixed in develop branch, will be included in next release