xfree86: common: gracefully handle allocation failure
Better try to handle memory allocation gracefully than just hard crashing by segfault. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
111ca8af21
commit
d3c4e100ed
|
@ -181,7 +181,9 @@ configureInputSection(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse = calloc(1, sizeof(XF86ConfInputRec));
|
if (!(mouse = calloc(1, sizeof(XF86ConfInputRec))))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
mouse->inp_identifier = XNFstrdup("Mouse0");
|
mouse->inp_identifier = XNFstrdup("Mouse0");
|
||||||
mouse->inp_driver = XNFstrdup("mouse");
|
mouse->inp_driver = XNFstrdup("mouse");
|
||||||
mouse->inp_option_lst =
|
mouse->inp_option_lst =
|
||||||
|
@ -213,9 +215,9 @@ configureScreenSection(int screennum)
|
||||||
ptr->scrn_device_str = tmp;
|
ptr->scrn_device_str = tmp;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(depths); i++) {
|
for (i = 0; i < ARRAY_SIZE(depths); i++) {
|
||||||
XF86ConfDisplayPtr conf_display;
|
XF86ConfDisplayPtr conf_display = calloc(1, sizeof(XF86ConfDisplayRec));
|
||||||
|
if (!conf_display)
|
||||||
conf_display = calloc(1, sizeof(XF86ConfDisplayRec));
|
continue;
|
||||||
conf_display->disp_depth = depths[i];
|
conf_display->disp_depth = depths[i];
|
||||||
conf_display->disp_black.red = conf_display->disp_white.red = -1;
|
conf_display->disp_black.red = conf_display->disp_white.red = -1;
|
||||||
conf_display->disp_black.green = conf_display->disp_white.green = -1;
|
conf_display->disp_black.green = conf_display->disp_white.green = -1;
|
||||||
|
@ -412,9 +414,9 @@ configureModuleSection(void)
|
||||||
elist = LoaderListDir("extensions", NULL);
|
elist = LoaderListDir("extensions", NULL);
|
||||||
if (elist) {
|
if (elist) {
|
||||||
for (el = elist; *el; el++) {
|
for (el = elist; *el; el++) {
|
||||||
XF86LoadPtr module;
|
XF86LoadPtr module = calloc(1, sizeof(XF86LoadRec));
|
||||||
|
if (!module)
|
||||||
module = calloc(1, sizeof(XF86LoadRec));
|
return ptr;
|
||||||
module->load_name = *el;
|
module->load_name = *el;
|
||||||
ptr->mod_load_lst = (XF86LoadPtr) xf86addListItem((glp) ptr->
|
ptr->mod_load_lst = (XF86LoadPtr) xf86addListItem((glp) ptr->
|
||||||
mod_load_lst,
|
mod_load_lst,
|
||||||
|
|
|
@ -844,13 +844,15 @@ xf86NameCmp(const char *s1, const char *s2)
|
||||||
char *
|
char *
|
||||||
xf86NormalizeName(const char *s)
|
xf86NormalizeName(const char *s)
|
||||||
{
|
{
|
||||||
char *ret, *q;
|
char *q;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = malloc(strlen(s) + 1);
|
char *ret = calloc(1, strlen(s) + 1);
|
||||||
|
if (!ret)
|
||||||
|
return NULL;
|
||||||
for (p = s, q = ret; *p != 0; p++) {
|
for (p = s, q = ret; *p != 0; p++) {
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '_':
|
case '_':
|
||||||
|
|
Loading…
Reference in New Issue