XFree86: Fix memory leak in option parsing

Fix option parsing functions and callers thereof to not leak memory.
This commit is contained in:
Magnus Vigerlöf 2007-04-10 23:48:00 +03:00 committed by Daniel Stone
parent 07c56abf84
commit 4771fa8747
5 changed files with 30 additions and 27 deletions

View File

@ -1271,7 +1271,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
(count + 1) * sizeof(IDevRec)); (count + 1) * sizeof(IDevRec));
indp[count - 1] = Pointer; indp[count - 1] = Pointer;
indp[count - 1].extraOptions = indp[count - 1].extraOptions =
xf86addNewOption(NULL, "CorePointer", NULL); xf86addNewOption(NULL, xnfstrdup("CorePointer"), NULL);
indp[count].identifier = NULL; indp[count].identifier = NULL;
servlayoutp->inputs = indp; servlayoutp->inputs = indp;
} }
@ -1310,7 +1310,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
(count + 1) * sizeof(IDevRec)); (count + 1) * sizeof(IDevRec));
indp[count - 1] = Pointer; indp[count - 1] = Pointer;
indp[count - 1].extraOptions = indp[count - 1].extraOptions =
xf86addNewOption(NULL, "AlwaysCore", NULL); xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), NULL);
indp[count].identifier = NULL; indp[count].identifier = NULL;
servlayoutp->inputs = indp; servlayoutp->inputs = indp;
} }
@ -1401,7 +1401,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
(count + 1) * sizeof(IDevRec)); (count + 1) * sizeof(IDevRec));
indp[count - 1] = Keyboard; indp[count - 1] = Keyboard;
indp[count - 1].extraOptions = indp[count - 1].extraOptions =
xf86addNewOption(NULL, "CoreKeyboard", NULL); xf86addNewOption(NULL, xnfstrdup("CoreKeyboard"), NULL);
indp[count].identifier = NULL; indp[count].identifier = NULL;
servlayoutp->inputs = indp; servlayoutp->inputs = indp;
} }

View File

@ -309,13 +309,16 @@ configureInputSection (void)
mouse->inp_identifier = "Mouse0"; mouse->inp_identifier = "Mouse0";
mouse->inp_driver = "mouse"; mouse->inp_driver = "mouse";
mouse->inp_option_lst = mouse->inp_option_lst =
xf86addNewOption(mouse->inp_option_lst, "Protocol", DFLT_MOUSE_PROTO); xf86addNewOption(mouse->inp_option_lst, xstrdup("Protocol"),
xstrdup(DFLT_MOUSE_PROTO));
#ifndef __SCO__ #ifndef __SCO__
mouse->inp_option_lst = mouse->inp_option_lst =
xf86addNewOption(mouse->inp_option_lst, "Device", DFLT_MOUSE_DEV); xf86addNewOption(mouse->inp_option_lst, xstrdup("Device"),
xstrdup(DFLT_MOUSE_DEV));
#endif #endif
mouse->inp_option_lst = mouse->inp_option_lst =
xf86addNewOption(mouse->inp_option_lst, "ZAxisMapping", "4 5 6 7"); xf86addNewOption(mouse->inp_option_lst, xstrdup("ZAxisMapping"),
xstrdup("4 5 6 7"));
ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse); ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse);
return ptr; return ptr;
} }
@ -519,7 +522,7 @@ configureLayoutSection (void)
iptr->iref_option_lst = NULL; iptr->iref_option_lst = NULL;
iptr->iref_inputdev_str = "Mouse0"; iptr->iref_inputdev_str = "Mouse0";
iptr->iref_option_lst = iptr->iref_option_lst =
xf86addNewOption (iptr->iref_option_lst, "CorePointer", NULL); xf86addNewOption (iptr->iref_option_lst, xstrdup("CorePointer"), NULL);
ptr->lay_input_lst = (XF86ConfInputrefPtr) ptr->lay_input_lst = (XF86ConfInputrefPtr)
xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
} }
@ -532,7 +535,7 @@ configureLayoutSection (void)
iptr->iref_option_lst = NULL; iptr->iref_option_lst = NULL;
iptr->iref_inputdev_str = "Keyboard0"; iptr->iref_inputdev_str = "Keyboard0";
iptr->iref_option_lst = iptr->iref_option_lst =
xf86addNewOption (iptr->iref_option_lst, "CoreKeyboard", NULL); xf86addNewOption (iptr->iref_option_lst, xstrdup("CoreKeyboard"), NULL);
ptr->lay_input_lst = (XF86ConfInputrefPtr) ptr->lay_input_lst = (XF86ConfInputrefPtr)
xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
} }
@ -751,7 +754,7 @@ configureDDCMonitorSection (int screennum)
} }
if (ConfiguredMonitor->features.dpms) { if (ConfiguredMonitor->features.dpms) {
ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, "DPMS", NULL); ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, xstrdup("DPMS"), NULL);
} }
return ptr; return ptr;

View File

@ -289,7 +289,7 @@ xf86CheckBoolOption(pointer optlist, const char *name, int deflt)
_X_EXPORT pointer _X_EXPORT pointer
xf86ReplaceIntOption(pointer optlist, const char *name, const int val) xf86ReplaceIntOption(pointer optlist, const char *name, const int val)
{ {
char *tmp = xnfalloc(16); char tmp[16];
sprintf(tmp,"%i",val); sprintf(tmp,"%i",val);
return xf86AddNewOption(optlist,name,tmp); return xf86AddNewOption(optlist,name,tmp);
} }
@ -297,7 +297,7 @@ xf86ReplaceIntOption(pointer optlist, const char *name, const int val)
_X_EXPORT pointer _X_EXPORT pointer
xf86ReplaceRealOption(pointer optlist, const char *name, const double val) xf86ReplaceRealOption(pointer optlist, const char *name, const double val)
{ {
char *tmp = xnfalloc(32); char tmp[32];
snprintf(tmp,32,"%f",val); snprintf(tmp,32,"%f",val);
return xf86AddNewOption(optlist,name,tmp); return xf86AddNewOption(optlist,name,tmp);
} }

View File

@ -198,21 +198,21 @@ addNewOption2 (XF86OptionPtr head, char *name, char *val, int used)
{ {
XF86OptionPtr new, old = NULL; XF86OptionPtr new, old = NULL;
/* Don't allow duplicates */ /* Don't allow duplicates, free old strings */
if (head != NULL && (old = xf86findOption(head, name)) != NULL) if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
new = old; new = old;
else { xf86conffree(new->opt_name);
xf86conffree(new->opt_val);
}
else
new = xf86confcalloc (1, sizeof (XF86OptionRec)); new = xf86confcalloc (1, sizeof (XF86OptionRec));
new->list.next = NULL; new->opt_name = name;
} new->opt_val = val;
new->opt_name = name; new->opt_used = used;
new->opt_val = val;
new->opt_used = used; if (old)
return head;
if (old == NULL) return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
else
return head;
} }
XF86OptionPtr XF86OptionPtr

View File

@ -2111,7 +2111,7 @@ LayoutConfig(void)
else else
iref->iref_option_lst = iref->iref_option_lst =
xf86addNewOption(iref->iref_option_lst, xf86addNewOption(iref->iref_option_lst,
"CorePointer", NULL); XtNewString("CorePointer"), NULL);
option = xf86findOption(mref->iref_option_lst, option = xf86findOption(mref->iref_option_lst,
"CorePointer"); "CorePointer");
XtFree(option->opt_name); XtFree(option->opt_name);
@ -2209,7 +2209,7 @@ LayoutConfig(void)
else else
iref->iref_option_lst = iref->iref_option_lst =
xf86addNewOption(iref->iref_option_lst, xf86addNewOption(iref->iref_option_lst,
"CoreKeyboard", NULL); XtNewString("CoreKeyboard"), NULL);
option = xf86findOption(kref->iref_option_lst, option = xf86findOption(kref->iref_option_lst,
"CoreKeyboard"); "CoreKeyboard");
XtFree(option->opt_name); XtFree(option->opt_name);