remote: fix clear_memid

Use a separate variable to iterate the mem_ids.
Clear some more fields.
This commit is contained in:
Wim Taymans 2018-02-13 10:28:01 +01:00
parent 8a4f3c546d
commit cc53023fb9
2 changed files with 8 additions and 3 deletions

View file

@ -72,6 +72,8 @@ struct pw_map_range {
uint32_t size; /** size to map */
};
#define PW_MAP_RANGE_INIT (struct pw_map_range){ 0, }
/** Calculate parameters to mmap() memory into \a range so that
* \a size bytes at \a offset can be mapped with mmap(). */
static inline void pw_map_range_init(struct pw_map_range *range,

View file

@ -584,9 +584,10 @@ static void *mem_map(struct node_data *data, struct mem_id *mid, uint32_t offset
}
static void mem_unmap(struct node_data *data, struct mem_id *mid)
{
if (mid->ptr) {
if (mid->ptr != NULL) {
if (munmap(mid->ptr, mid->map.size) < 0)
pw_log_warn("failed to unmap: %m");
mid->ptr = NULL;
}
}
@ -595,12 +596,13 @@ static void clear_memid(struct node_data *data, struct mem_id *mid)
if (mid->fd != -1) {
bool has_ref = false;
int fd;
struct mem_id *m;
fd = mid->fd;
mid->fd = -1;
pw_array_for_each(mid, &data->mem_ids) {
if (mid->fd == fd) {
pw_array_for_each(m, &data->mem_ids) {
if (m->fd == fd) {
has_ref = true;
break;
}
@ -687,6 +689,7 @@ static void client_node_add_mem(void *object,
m->fd = memfd;
m->flags = flags;
m->ref = 0;
m->map = PW_MAP_RANGE_INIT;
m->ptr = NULL;
}