summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Simiklit <andrii.simiklit@globallogic.com>2020-01-15 12:34:38 +0200
committerEric Engestrom <eric@engestrom.ch>2020-03-06 22:59:39 +0100
commitd9ee96ba69c0265d80c35c891ab82c9f80b6cf83 (patch)
treeb5bd0a210028884c5927803904f35fa02b91fb7c
parent5947cf61d2d393c1036891ec54fd2ce2e72d64b8 (diff)
Revert "glx: convert glx_config_create_list to one big calloc"
This reverts commit 35fc7bdf0e6ad6547e39099e7060a3d89539b56d. Unfortunately mentioned commit introduced a memory leak because `driwindowsMapConfigs` and `createDriMode` functions allocate small memory portions for each element: 21,576 (232 direct, 21,344 indirect) bytes in 1 blocks are definitely lost in loss record 1,411 of 1,414 at 0x483A7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5D4AA09: createDriMode (dri_common.c:291) by 0x5D4ABF5: driConvertConfigs (dri_common.c:310) by 0x5D58414: dri3_create_screen (dri3_glx.c:945) by 0x5D39829: AllocAndFetchScreenConfigs (glxext.c:815) by 0x5D39C57: __glXInitialize (glxext.c:941) by 0x5D3290A: GetGLXPrivScreenConfig (glxcmds.c:174) by 0x5D34F38: glXQueryExtensionsString (glxcmds.c:1307) by 0x4F83038: glXQueryExtensionsString (in /usr/local/lib/libGL.so.1.7.0) by 0x4F2EA6B: ??? (in /usr/lib/x86_64-linux-gnu/libwaffle-1.so.0.6.0) by 0x4F2A0D7: waffle_display_connect (in /usr/lib/x86_64-linux-gnu/libwaffle-1.so.0.6.0) by 0x498F42A: wfl_checked_display_connect (piglit-util-waffle.h:74) There is one more thing which disallow us to easily fix it are different element sizes for instance: `glx_config_create_list` allocates memory just for `glx_config`, `driwindowsMapConfigs` for `driwindows_config` and `createDriMode` for `__GLXDRIconfigPrivate`. Yes it is possible but size of such fix will be more big and complex than original one. So it make sense only if the malloc overhead really is a big problem there. Acked-by: Eric Engestrom <eric@engestrom.ch> Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com> Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3406> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3406> (cherry picked from commit 311c82e1923f63070b198881d90c1098f4ff7a08)
-rw-r--r--.pick_status.json2
-rw-r--r--src/glx/glxconfig.c63
2 files changed, 38 insertions, 27 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 241ed9ff4f2..1a945a92853 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1363,7 +1363,7 @@
"description": "Revert \"glx: convert glx_config_create_list to one big calloc\"",
"nominated": true,
"nomination_type": 2,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "35fc7bdf0e6ad6547e39099e7060a3d89539b56d"
},
diff --git a/src/glx/glxconfig.c b/src/glx/glxconfig.c
index 569d24bfac5..6c4267c8f39 100644
--- a/src/glx/glxconfig.c
+++ b/src/glx/glxconfig.c
@@ -218,43 +218,54 @@ glx_config_get(struct glx_config * mode, int attribute, int *value_return)
_X_HIDDEN struct glx_config *
glx_config_create_list(unsigned count)
{
- struct glx_config *c = NULL;
+ const size_t size = sizeof(struct glx_config);
+ struct glx_config *base = NULL;
+ struct glx_config **next;
unsigned i;
- if (!(c = calloc(count, sizeof(struct glx_config))))
- return NULL;
-
+ next = &base;
for (i = 0; i < count; i++) {
- c[i].visualID = GLX_DONT_CARE;
- c[i].visualType = GLX_DONT_CARE;
- c[i].visualRating = GLX_NONE;
- c[i].transparentPixel = GLX_NONE;
- c[i].transparentRed = GLX_DONT_CARE;
- c[i].transparentGreen = GLX_DONT_CARE;
- c[i].transparentBlue = GLX_DONT_CARE;
- c[i].transparentAlpha = GLX_DONT_CARE;
- c[i].transparentIndex = GLX_DONT_CARE;
- c[i].xRenderable = GLX_DONT_CARE;
- c[i].fbconfigID = GLX_DONT_CARE;
- c[i].swapMethod = GLX_SWAP_UNDEFINED_OML;
- c[i].bindToTextureRgb = GLX_DONT_CARE;
- c[i].bindToTextureRgba = GLX_DONT_CARE;
- c[i].bindToMipmapTexture = GLX_DONT_CARE;
- c[i].bindToTextureTargets = GLX_DONT_CARE;
- c[i].yInverted = GLX_DONT_CARE;
- c[i].sRGBCapable = GLX_DONT_CARE;
+ *next = calloc(1, size);
+ if (*next == NULL) {
+ glx_config_destroy_list(base);
+ base = NULL;
+ break;
+ }
+
+ (*next)->visualID = GLX_DONT_CARE;
+ (*next)->visualType = GLX_DONT_CARE;
+ (*next)->visualRating = GLX_NONE;
+ (*next)->transparentPixel = GLX_NONE;
+ (*next)->transparentRed = GLX_DONT_CARE;
+ (*next)->transparentGreen = GLX_DONT_CARE;
+ (*next)->transparentBlue = GLX_DONT_CARE;
+ (*next)->transparentAlpha = GLX_DONT_CARE;
+ (*next)->transparentIndex = GLX_DONT_CARE;
+ (*next)->xRenderable = GLX_DONT_CARE;
+ (*next)->fbconfigID = GLX_DONT_CARE;
+ (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
+ (*next)->bindToTextureRgb = GLX_DONT_CARE;
+ (*next)->bindToTextureRgba = GLX_DONT_CARE;
+ (*next)->bindToMipmapTexture = GLX_DONT_CARE;
+ (*next)->bindToTextureTargets = GLX_DONT_CARE;
+ (*next)->yInverted = GLX_DONT_CARE;
+ (*next)->sRGBCapable = GLX_DONT_CARE;
- if (i != count -1)
- c[i].next = &(c[i+1]);
+ next = &((*next)->next);
}
- return c;
+ return base;
}
_X_HIDDEN void
glx_config_destroy_list(struct glx_config *configs)
{
- free(configs);
+ while (configs != NULL) {
+ struct glx_config *const next = configs->next;
+
+ free(configs);
+ configs = next;
+ }
}