Skip to content

daxctl_dev_get_memory allocation issue #112

Description

@michalbiesek

General Information

I try to to retrieve information about device-dax which are configured in "system-ram" mode.
For this scenario I use daxctl_dev_get_memory function.
See Implementation details below.

Implementation details

#include <daxctl/libdaxctl.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    struct daxctl_ctx *ctx;
    struct daxctl_region *region;
    struct daxctl_dev *dev;


    int rc = daxctl_new(&ctx);
    if (rc < 0)
        return -1;

    daxctl_region_foreach(ctx, region) {
        daxctl_dev_foreach(region, dev) {
            struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
            if (mem) {
              int node = daxctl_dev_get_target_node(dev);
              printf("Node %d", node); 
            }
            free(mem);    ////potential issue
        }
    }

    daxctl_unref(ctx);
    return 0;
}

I saw that there is memory allocation in:

mem = calloc(1, sizeof(*mem));

Currently I see potential issue that I don't know if could call free on struct daxctl_memory * or not, since there are 2 way to get struct daxctl_memory:

ndctl/daxctl/lib/libdaxctl.c

Lines 1064 to 1067 in cec5975

if (dev->mem)
return dev->mem;
else
return daxctl_dev_alloc_mem(dev);

Additional Information

I think that this operation in case of memory allocation could result with memory leak in e.g.:

struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
in case of daxctl device is configured as system-mode-ram

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions