Skip to content

FlashIAP::init - Possible memory leak/OOM error #12439

@dustin-crossman

Description

@dustin-crossman

Description of defect

If a targets flash_init() returns an errror, FlashIAP::init() will catch this and set its own return code properly, however, it does not return early. As a result it will call get_page_size() and then use new to allocate a page.
This can lead to two problems:

  1. If new allocates successfully a memory leak may occur because the user will not expect (and should not be expected) to call deinit() after a failed init.
  2. If get_page_size() returns wrong/junk data new may be called with a very large value and cause an Out of Memory error.

Issue #2 was seen in practice while we were testing changes to our flash driver which caused it to fail on init and which therefore caused get_page_size() to return an uninitialized value.

Target(s) affected by this defect ?

All

Toolchain(s) (name and version) displaying this defect ?

All

What version of Mbed-os are you using (tag or sha) ?

master
sha: 3d038e5

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

N/A

How is this defect reproduced ?

Modify a targets flash_init() to return failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions