Memory leak in sComboBoxes.pas

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38197
    Lasse
    Participant

    There is a memory leak in sComboBoxes.pas:

    Code:
    2136:procedure PrepareColors;
    2137:begin
    2138: if ColorsHolder = nil then begin
    2139: ColorsHolder := TacColorsHolder.Create;
    2140: ColorsHolder.acPrettyNames := TStringList.Create; // <= This is not needed, see constructor TacColorsHolder.Create;
    2141: GetColorValues(ColorsHolder.acColorCallBack);
    2142: end;
    2143:end;

    Code:
    3211:finalization
    3212: {$IFDEF DELPHI6UP}
    3213: if ColorsHolder = nil then // <= This should be if Assigned(ColorsHolder) then
    3214: ColorsHolder.Free;
    #59256
    Support
    Keymaster

    Thank you, code will be changed in the nearest release.

    Quote:
    if ColorsHolder = nil then // <= This should be if Assigned(ColorsHolder) then

    Why this line should be changed?

    #59257
    Lasse
    Participant

    There is no reason to free an object if it is already nil (that would be an AV). That causes a part of that memory leak. Another part comes from the string list that is created twice.

    Code:
    if ColorsHolder nil then
    ColorsHolder.Free;

    Would make sense but ColorsHolder = nil does not… I rather use Assigned and not Assigned than nil and = nil…

    #59258
    Support
    Keymaster

    Ahh, really.. My mistake.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.