Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pipewire pipewire
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 576
    • Issues 576
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 22
    • Merge requests 22
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PipeWirePipeWire
  • pipewirepipewire
  • Issues
  • #1247
Closed
Open
Issue created May 29, 2021 by Barnabás Pőcze@pobrnContributor

`pw_map_insert_at()` does not update free list which may result in lost elements

If pw_map_insert_at is used to insert to an id which was previously removed, then the free list may become corrupted:

#include <stdio.h>
#include <pipewire/map.h>

static int f(void *data, void *context)
{
        (void) context;

        printf("%s\n", data);

        return 0;
}

int main(void) {
        static const char * const strs[] = { "A", "B", "C" };

        struct pw_map m;
        pw_map_init(&m, 16, sizeof(strs[0]));

        uint32_t id = pw_map_insert_new(&m, strs[0]);
        pw_map_remove(&m, id);

        pw_map_insert_at(&m, id, strs[1]);
        pw_map_insert_new(&m, strs[2]);

        pw_map_for_each(&m, f, NULL);

        pw_map_clear(&m);

        return 0;
}

The code above prints:

C

instead of

B
C

since the index of the previously inserted B hasn't been removed from the free list, in this case, m.free_list == id even after the pw_map_insert_at() call, thus the next pw_map_insert_new() will override the data.

This limitation doesn't seem to be documented anywhere, am I missing something? I suppose this is the expected behaviour?

Assignee
Assign to
Time tracking