[JASS] Does this short code cause memory leak?

Status
Not open for further replies.
JASS:
function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsOfPlayerAll takes player whichPlayer returns group
    return GetUnitsOfPlayerMatching(whichPlayer, null)
endfunction
So yeah, your code leaks.

Instead of setting local group to new group handle (CreateGroup) and then resetting it to function return value (leak comes from there, you havent destoyed previously allocated handle object) you should do:
JASS:
local group g = GetUnitsOfPlayerAll(Player(0))
 
Status
Not open for further replies.
Back
Top