Menu

False memleak when passing memory back through arguement

2021-05-03
2021-05-09
  • Curtis Malainey

    Curtis Malainey - 2021-05-03

    I am getting a memleak error here
    https://github.com/thesofproject/rimage/blob/main/src/ext_manifest.c#L134.
    (snippet below for history) on variable buffer. But as you can see, the
    buffer is passed back through the double pointer argument.

    rimage/src/ext_manifest.c:134:2: error: Memory leak: buffer [memleak]
    return ret;

    ^

    static int ext_man_build(const struct module module,
    struct ext_man_header
    dst_buff)
    {
    ...
    /
    alloc buffer for ext_man */
    buffer = calloc(1, ext_man.full_size);
    if (!buffer) {
    ret = -ENOMEM;
    goto out;
    }

    / fill buffer with ext_man and section content /
    memcpy(buffer, &ext_man, ext_man.header_size);
    offset = ext_man.header_size;

    memcpy(&buffer[offset], sec_buffer, section->size);

    dst_buff = (struct ext_man_header )buffer;

    out:
    free(sec_buffer);
    return ret;
    }

     
  • CHR

    CHR - 2021-05-04

    Could you provide a self-contained example? The file without headers is clean with 2.4.1.

     
  • rikard

    rikard - 2021-05-09

    I can reproduce with 2.3, but not 2.4. This was fixed in https://trac.cppcheck.net/ticket/10186.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.