This would be nicer as a new helper function in u_hash_table.c that returns the count or is_empty.
Marek On Tue, May 8, 2018 at 5:07 PM, Jan Vesely <jan.ves...@rutgers.edu> wrote: > Fixes memory leak on module unload. > CC: <mesa-sta...@lists.freedesktop.org> > Signed-off-by: Jan Vesely <jan.ves...@rutgers.edu> > --- > Not the prettiest way to do this, but it works and imo shouldn't need > anything more fancy. > > src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c > b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c > index 3ee243adbc..f4555a1dc8 100644 > --- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c > +++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c > @@ -707,10 +707,17 @@ static int compare_fd(void *key1, void *key2) > > DEBUG_GET_ONCE_BOOL_OPTION(thread, "RADEON_THREAD", true) > > +static enum pipe_error inc(void *k, void *v, void *d) > +{ > + (*(size_t *)d) += 1; > + return PIPE_OK; > +} > + > static bool radeon_winsys_unref(struct radeon_winsys *ws) > { > struct radeon_drm_winsys *rws = (struct radeon_drm_winsys*)ws; > bool destroy; > + size_t count = 0; > > /* When the reference counter drops to zero, remove the fd from the > table. > * This must happen while the mutex is locked, so that > @@ -719,8 +726,14 @@ static bool radeon_winsys_unref(struct radeon_winsys > *ws) > mtx_lock(&fd_tab_mutex); > > destroy = pipe_reference(&rws->reference, NULL); > - if (destroy && fd_tab) > + if (destroy && fd_tab) { > util_hash_table_remove(fd_tab, intptr_to_pointer(rws->fd)); > + util_hash_table_foreach(fd_tab, inc, &count); > + if (count == 0) { > + util_hash_table_destroy(fd_tab); > + fd_tab = NULL; > + } > + } > > mtx_unlock(&fd_tab_mutex); > return destroy; > -- > 2.17.0 > >
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev