回复: [edk2-discuss] Memory leak in the BootManager code


gaoliming
 

Yes. The allocated HelpString is required to be free after HiiSetString.

Thanks
Liming

-----邮件原件-----
发件人: discuss@edk2.groups.io <discuss@edk2.groups.io> 代表
Konstantin Aladyshev
发送时间: 2022年10月2日 5:17
收件人: discuss <discuss@edk2.groups.io>; zhichao.gao@...; Ni, Ray
<ray.ni@...>
主题: [edk2-discuss] Memory leak in the BootManager code

Hello!

I have a question about dynamic content generation in the form
EFI_HII_CONFIG_ACCESS_PROTOCOL.Callback() code.
Usually such content is generated with the help of labels on the
EFI_BROWSER_ACTION_FORM_OPEN action. Example is the BootManager
form.

The thing that I want to discuss is that strings for the generated
elements are produced via the `HiiSetString(HiiHandle, 0, <Text>,
NULL)` calls.
But if we use 0 as the second argument, this would produce new string
packages every time we enter the BootManager form. Isn't it a memory
leak?

Example:
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Library/Bo
otManagerUiLib/BootManager.c

BootManagerCallback() calls UpdateBootManager() on each form open
which creates new strings via:
```
Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL);
HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);
```

Best regards,
Konstantin Aladyshev