From 3d7cb106afb680c9a1310681ad28048d39df33b5 Mon Sep 17 00:00:00 2001 From: kojima Date: Wed, 29 Mar 2000 03:58:25 +0000 Subject: [PATCH] fixed memory leaks and crash with deminiaturization --- src/defaults.c | 4 ++-- src/dock.c | 51 ++++++++++++++++++++++++++++----------------------- src/event.c | 9 +++++---- src/misc.c | 35 ++++++++++++++++++++++++----------- src/xmodifier.c | 2 +- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/defaults.c b/src/defaults.c index 97289aa7..e5ab85f2 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -2751,7 +2751,7 @@ setClearance(WScreen *scr, WDefaultEntry *entry, void *bar, void *foo) } static int -setIfDockPresent(WScreen *scr, WDefaultEntry *entry, int *flag, long which) +setIfDockPresent(WScreen *scr, WDefaultEntry *entry, char *flag, long which) { switch (which) { case WM_DOCK: @@ -3424,7 +3424,7 @@ setDoubleClick(WScreen *scr, WDefaultEntry *entry, int *value, void *foo) static int -setMultiByte(WScreen *scr, WDefaultEntry *entry, int *value, void *foo) +setMultiByte(WScreen *scr, WDefaultEntry *entry, char *value, void *foo) { extern _WINGsConfiguration WINGsConfiguration; diff --git a/src/dock.c b/src/dock.c index 157b2e66..07c31b1e 100644 --- a/src/dock.c +++ b/src/dock.c @@ -1535,9 +1535,7 @@ static WAppIcon* restore_icon_state(WScreen *scr, proplist_t info, int type, int index) { WAppIcon *aicon; - char *wclass, *winstance; proplist_t cmd, value; - char *command; cmd = PLGetDictionaryEntry(info, dCommand); @@ -1550,37 +1548,44 @@ restore_icon_state(WScreen *scr, proplist_t info, int type, int index) if (!value) return NULL; - ParseWindowName(value, &winstance, &wclass, "dock"); + { + char *wclass, *winstance; + char *command; - if (!winstance && !wclass) { - return NULL; - } + ParseWindowName(value, &winstance, &wclass, "dock"); + + if (!winstance && !wclass) { + return NULL; + } - /* get commands */ + /* get commands */ - if (cmd) - command = wstrdup(PLGetString(cmd)); - else - command = NULL; + if (cmd) + command = wstrdup(PLGetString(cmd)); + else + command = NULL; - if (!command || strcmp(command, "-")==0) { - if (command) - free(command); + if (!command || strcmp(command, "-")==0) { + if (command) + free(command); + if (wclass) + free(wclass); + if (winstance) + free(winstance); + + return NULL; + } + + aicon = wAppIconCreateForDock(scr, command, winstance, wclass, + TILE_NORMAL); if (wclass) free(wclass); if (winstance) free(winstance); - - return NULL; + if (command) + free(command); } - aicon = wAppIconCreateForDock(scr, command, winstance, wclass, - TILE_NORMAL); - if (wclass) - free(wclass); - if (winstance) - free(winstance); - aicon->icon->core->descriptor.handle_mousedown = iconMouseDown; if (type == WM_CLIP) { aicon->icon->core->descriptor.handle_enternotify = clipEnterNotify; diff --git a/src/event.c b/src/event.c index e6c4d5cb..7b9d17d4 100644 --- a/src/event.c +++ b/src/event.c @@ -653,6 +653,7 @@ handleButtonPress(XEvent *event) } #endif /* !LITE */ + desc = NULL; if (XFindContext(dpy, event->xbutton.subwindow, wWinContext, (XPointer *)&desc)==XCNOENT) { if (XFindContext(dpy, event->xbutton.window, wWinContext, @@ -661,10 +662,6 @@ handleButtonPress(XEvent *event) } } - if (desc->handle_mousedown!=NULL) { - (*desc->handle_mousedown)(desc, event); - } - if (desc->parent_type == WCLASS_WINDOW) { XSync(dpy, 0); @@ -689,6 +686,10 @@ handleButtonPress(XEvent *event) } } + if (desc->handle_mousedown!=NULL) { + (*desc->handle_mousedown)(desc, event); + } + /* save double-click information */ if (scr->flags.next_click_is_not_double) { scr->flags.next_click_is_not_double = 0; diff --git a/src/misc.c b/src/misc.c index 06a05b81..627cfed7 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1164,6 +1164,19 @@ keysymToString(KeySym keysym, unsigned int state) } #endif +static char * +appendrealloc(char *a, char *b) +{ + if (a == NULL) + return wstrdup(b); + else { + char *c = wstrappend(a, b); + free(a); + return c; + } +} + + char* GetShortcutString(char *text) { @@ -1189,33 +1202,33 @@ GetShortcutString(char *text) modmask |= mod; if (strcasecmp(text, "Meta")==0) { - buffer = wstrappend(buffer, "M+"); + buffer = appendrealloc(buffer, "M+"); } else if (strcasecmp(text, "Alt")==0) { - buffer = wstrappend(buffer, "A+"); + buffer = appendrealloc(buffer, "A+"); } else if (strcasecmp(text, "Shift")==0) { - buffer = wstrappend(buffer, "Sh+"); + buffer = appendrealloc(buffer, "Sh+"); } else if (strcasecmp(text, "Mod1")==0) { - buffer = wstrappend(buffer, "M1+"); + buffer = appendrealloc(buffer, "M1+"); } else if (strcasecmp(text, "Mod2")==0) { - buffer = wstrappend(buffer, "M2+"); + buffer = appendrealloc(buffer, "M2+"); } else if (strcasecmp(text, "Mod3")==0) { - buffer = wstrappend(buffer, "M3+"); + buffer = appendrealloc(buffer, "M3+"); } else if (strcasecmp(text, "Mod4")==0) { - buffer = wstrappend(buffer, "M4+"); + buffer = appendrealloc(buffer, "M4+"); } else if (strcasecmp(text, "Mod5")==0) { - buffer = wstrappend(buffer, "M5+"); + buffer = appendrealloc(buffer, "M5+"); } else if (strcasecmp(text, "Control")==0) { control = 1; } else { - buffer = wstrappend(buffer, text); + buffer = appendrealloc(buffer, text); } text = k+1; } if (control) { - buffer = wstrappend(buffer, "^"); + buffer = appendrealloc(buffer, "^"); } - buffer = wstrappend(buffer, text); + buffer = appendrealloc(buffer, text); /* get key */ /* ksym = XStringToKeysym(text); diff --git a/src/xmodifier.c b/src/xmodifier.c index 08aa87cd..729cb865 100644 --- a/src/xmodifier.c +++ b/src/xmodifier.c @@ -256,7 +256,7 @@ x_reset_modifier_mapping (Display *display) " by the keysyms used to control those bits. Mod1 does NOT always\n" " mean Meta, although some non-ICCCM-compliant programs assume that.\n"); #endif - XFree(x_modifier_keymap); + XFreeModifiermap(x_modifier_keymap); } -- 2.11.4.GIT