From 5ae4b6693a8254236435960ef84701fe405fe59b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 6 Dec 2010 14:38:23 +0800 Subject: egl: _eglFilterArray should not allocate. Otherwise, when it is called from within a driver, the caller cannot free the returned data (on Windows). --- src/gallium/state_trackers/egl/common/egl_g3d_api.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/gallium/state_trackers/egl') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c index f505220222..8e53e1dccb 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -141,11 +141,22 @@ egl_g3d_choose_config(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attribs, if (!_eglParseConfigAttribList(&criteria, dpy, attribs)) return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); - tmp_configs = (_EGLConfig **) _eglFilterArray(dpy->Configs, &tmp_size, + /* get the number of matched configs */ + tmp_size = _eglFilterArray(dpy->Configs, NULL, 0, (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); + if (!tmp_size) { + *num_configs = tmp_size; + return EGL_TRUE; + } + + tmp_configs = MALLOC(sizeof(tmp_configs[0]) * tmp_size); if (!tmp_configs) return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); + /* get the matched configs */ + _eglFilterArray(dpy->Configs, (void **) tmp_configs, tmp_size, + (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); + /* perform sorting of configs */ if (tmp_configs && tmp_size) { _eglSortConfigs((const _EGLConfig **) tmp_configs, tmp_size, @@ -155,7 +166,7 @@ egl_g3d_choose_config(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attribs, configs[i] = _eglGetConfigHandle(tmp_configs[i]); } - free(tmp_configs); + FREE(tmp_configs); *num_configs = size; -- cgit v1.2.3