sonar-openedge icon indicating copy to clipboard operation
sonar-openedge copied to clipboard

Flag if valid-handle( a ) then delete object b.

Open stefandrissen opened this issue 5 years ago • 3 comments

Since no-error is frowned upon by one of the rules, we've been changing a lot of delete object a no-error to:

if valid-handle( a ) then
   delete object a.

And before you know it something like the following happens:

if valid-handle( a ) then 
   delete object a.
if valid-handle( a ) then 
   delete object b.

With, as a result, object b leaking.

Optionally some smartness could be included for table-handles:

if valid-handle( hb ) then
   delete object hb:table-handle.

stefandrissen avatar Oct 09 '19 06:10 stefandrissen

Maybe an "unused valid object" rule ? Fired whenever an object is checked for validity without being used.

If created I think valid-handle and valid-object should be treated equally.

cave-at, usage could be within the same expression. e.g. `if valid-handle(hb) and hb:available then ...

cverbiest avatar Oct 09 '19 07:10 cverbiest

In my case both objects were used, only the delete of one was conditional due to the 'typo' checking the wrong variable. ie I had a massive memory leak (these were x-noderefs)

stefandrissen avatar Oct 09 '19 11:10 stefandrissen

With my suggestion the unused valid object rule would flag object a on the second if.

   delete object a.
/* this if get flagged */ if valid-handle( a ) then 
   delete object b.

It is the if statement that gets flagged because it use a valid-handle test on an object that is not used in the then block.

cverbiest avatar Oct 11 '19 10:10 cverbiest