Skip to content

Avoid the use of malloc() and free(). #6557

@bangerth

Description

@bangerth

In structured_data.cc, we do

        char *filename = static_cast<char *>(std::malloc (maxsize * sizeof(char)));
        int ret = std::snprintf (filename,
                                 maxsize,
                                 filename_and_path.c_str(),
                                 boundary_name.c_str(),
                                 filenumber);

        AssertThrow(ret >= 0, ExcMessage("Invalid string placeholder in filename detected."));
        AssertThrow(ret< maxsize, ExcInternalError("snprintf string overflow detected."));
        const std::string str_result (filename);
        std::free (filename);

We should avoid the use of malloc() and free() and instead replace the explicit memory allocation via the use of a std::unique_ptr and std::make_unique().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions