least intrusive way to plug a memleak when unbinding a duplicate key for

kbfunc_cmdexec; from Tiago Cunha
This commit is contained in:
okan 2013-01-01 14:33:52 +00:00
parent f67f32f8a5
commit 572328d529
2 changed files with 10 additions and 3 deletions

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: calmwm.h,v 1.180 2013/01/01 14:19:56 okan Exp $ * $OpenBSD: calmwm.h,v 1.181 2013/01/01 14:33:52 okan Exp $
*/ */
#ifndef _CALMWM_H_ #ifndef _CALMWM_H_
@ -74,6 +74,8 @@
#define CWM_MENU_DUMMY 0x0001 #define CWM_MENU_DUMMY 0x0001
#define CWM_MENU_FILE 0x0002 #define CWM_MENU_FILE 0x0002
#define ARG_CHAR 0x0001
#define ARG_INT 0x0002
union arg { union arg {
char *c; char *c;
int i; int i;
@ -239,6 +241,7 @@ struct keybinding {
int keycode; int keycode;
#define KBFLAG_NEEDCLIENT 0x0001 #define KBFLAG_NEEDCLIENT 0x0001
int flags; int flags;
int argtype;
}; };
TAILQ_HEAD(keybinding_q, keybinding); TAILQ_HEAD(keybinding_q, keybinding);

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: conf.c,v 1.116 2012/12/19 15:21:34 okan Exp $ * $OpenBSD: conf.c,v 1.117 2013/01/01 14:33:52 okan Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -470,14 +470,16 @@ conf_bindname(struct conf *c, char *name, char *binding)
current_binding->callback = name_to_kbfunc[i].handler; current_binding->callback = name_to_kbfunc[i].handler;
current_binding->flags = name_to_kbfunc[i].flags; current_binding->flags = name_to_kbfunc[i].flags;
current_binding->argument = name_to_kbfunc[i].argument; current_binding->argument = name_to_kbfunc[i].argument;
current_binding->argtype |= ARG_INT;
conf_grab(c, current_binding); conf_grab(c, current_binding);
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry); TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
return; return;
} }
current_binding->callback = kbfunc_cmdexec; current_binding->callback = kbfunc_cmdexec;
current_binding->argument.c = xstrdup(binding);
current_binding->flags = 0; current_binding->flags = 0;
current_binding->argument.c = xstrdup(binding);
current_binding->argtype |= ARG_CHAR;
conf_grab(c, current_binding); conf_grab(c, current_binding);
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry); TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
} }
@ -496,6 +498,8 @@ conf_unbind(struct conf *c, struct keybinding *unbind)
key->keysym == unbind->keysym) { key->keysym == unbind->keysym) {
conf_ungrab(c, key); conf_ungrab(c, key);
TAILQ_REMOVE(&c->keybindingq, key, entry); TAILQ_REMOVE(&c->keybindingq, key, entry);
if (key->argtype & ARG_CHAR)
free(key->argument.c);
free(key); free(key);
} }
} }