mirror of
https://github.com/gryf/wmaker.git
synced 2026-11-20 06:06:55 +01:00
wrlib: release context resources on RCreateContext() failure
RCreateContext() duplicates the attributes and creates a GC before it validates the visual and sets up the colormap. Its failure paths only called free(context), which leaks the attributes structure and the GC each time a context cannot be created (bad visual ID, colormap setup failure, gray scale allocation failure). Use RDestroyContext() on these paths so that everything allocated so far is released. Since the visual-ID failure happens before any drawable window is created, make RDestroyContext() destroy the drawable only when one exists, instead of calling XDestroyWindow() on None. Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
This commit is contained in:
1 parent
0dd8b6a099
commit
9c2b6865be
1 file changed
+5
-4
+5
-4
@@ -567,7 +567,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
||||
templ.visualid = context->attribs->visualid;
|
||||
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask, &templ, &nret);
|
||||
if (!vinfo || nret == 0) {
|
||||
free(context);
|
||||
RDestroyContext(context);
|
||||
RErrorCode = RERR_BADVISUALID;
|
||||
return NULL;
|
||||
}
|
||||
@@ -614,13 +614,13 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
|
||||
|
||||
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
|
||||
if (!setupPseudoColorColormap(context)) {
|
||||
free(context);
|
||||
RDestroyContext(context);
|
||||
return NULL;
|
||||
}
|
||||
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
|
||||
context->colors = allocateGrayScale(context);
|
||||
if (!context->colors) {
|
||||
free(context);
|
||||
RDestroyContext(context);
|
||||
return NULL;
|
||||
}
|
||||
} else if (context->vclass == TrueColor) {
|
||||
@@ -665,7 +665,8 @@ void RDestroyContext(RContext *context)
|
||||
XFreeGC(context->dpy, context->copy_gc);
|
||||
if (context->attribs) {
|
||||
if ((context->attribs->flags & RC_VisualID) &&
|
||||
!(context->attribs->flags & RC_DefaultVisual))
|
||||
!(context->attribs->flags & RC_DefaultVisual) &&
|
||||
context->drawable != None)
|
||||
XDestroyWindow(context->dpy, context->drawable);
|
||||
free(context->attribs);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user