Coverity #813, #814, #815, #816: Fix resource leaks in error paths of

config parsing code.
This commit is contained in:
Eric Anholt 2006-03-10 07:58:27 +00:00
parent 2bd4110549
commit 55f677d600
4 changed files with 48 additions and 14 deletions

View File

@ -1,3 +1,11 @@
2006-03-09 Eric Anholt <anholt@FreeBSD.org>
* hw/xfree86/parser/Keyboard.c: (xf86parseKeyboardSection):
* hw/xfree86/parser/Layout.c: (xf86parseLayoutSection):
* hw/xfree86/parser/Pointer.c: (xf86parsePointerSection):
Coverity #813, #814, #815, #816: Fix resource leaks in error paths of
config parsing code.
2006-03-09 Eric Anholt <anholt@FreeBSD.org> 2006-03-09 Eric Anholt <anholt@FreeBSD.org>
* exa/exa.h: * exa/exa.h:

View File

@ -139,8 +139,10 @@ xf86parseKeyboardSection (void)
if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER)
Error (AUTOREPEAT_MSG, NULL); Error (AUTOREPEAT_MSG, NULL);
s1 = xf86uLongToString(val.num); s1 = xf86uLongToString(val.num);
if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER) {
xf86conffree(s1);
Error (AUTOREPEAT_MSG, NULL); Error (AUTOREPEAT_MSG, NULL);
}
s2 = xf86uLongToString(val.num); s2 = xf86uLongToString(val.num);
l = strlen(s1) + 1 + strlen(s2) + 1; l = strlen(s1) + 1 + strlen(s2) + 1;
s = xf86confmalloc(l); s = xf86confmalloc(l);

View File

@ -119,8 +119,10 @@ xf86parseLayoutSection (void)
iptr = xf86confcalloc (1, sizeof (XF86ConfInactiveRec)); iptr = xf86confcalloc (1, sizeof (XF86ConfInactiveRec));
iptr->list.next = NULL; iptr->list.next = NULL;
if (xf86getSubToken (&(ptr->lay_comment)) != STRING) if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
xf86conffree (iptr);
Error (INACTIVE_MSG, NULL); Error (INACTIVE_MSG, NULL);
}
iptr->inactive_device_str = val.str; iptr->inactive_device_str = val.str;
ptr->lay_inactive_lst = (XF86ConfInactivePtr) ptr->lay_inactive_lst = (XF86ConfInactivePtr)
xf86addListItem ((glp) ptr->lay_inactive_lst, (glp) iptr); xf86addListItem ((glp) ptr->lay_inactive_lst, (glp) iptr);
@ -143,8 +145,10 @@ xf86parseLayoutSection (void)
else else
xf86unGetToken (token); xf86unGetToken (token);
token = xf86getSubToken(&(ptr->lay_comment)); token = xf86getSubToken(&(ptr->lay_comment));
if (token != STRING) if (token != STRING) {
xf86conffree(aptr);
Error (SCREEN_MSG, NULL); Error (SCREEN_MSG, NULL);
}
aptr->adj_screen_str = val.str; aptr->adj_screen_str = val.str;
token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab); token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab);
@ -170,6 +174,7 @@ xf86parseLayoutSection (void)
absKeyword = 1; absKeyword = 1;
break; break;
case EOF_TOKEN: case EOF_TOKEN:
xf86conffree(aptr);
Error (UNEXPECTED_EOF_MSG, NULL); Error (UNEXPECTED_EOF_MSG, NULL);
break; break;
default: default:
@ -189,13 +194,16 @@ xf86parseLayoutSection (void)
{ {
aptr->adj_x = val.num; aptr->adj_x = val.num;
token = xf86getSubToken(&(ptr->lay_comment)); token = xf86getSubToken(&(ptr->lay_comment));
if (token != NUMBER) if (token != NUMBER) {
xf86conffree(aptr);
Error(INVALID_SCR_MSG, NULL); Error(INVALID_SCR_MSG, NULL);
}
aptr->adj_y = val.num; aptr->adj_y = val.num;
} else { } else {
if (absKeyword) if (absKeyword) {
xf86conffree(aptr);
Error(INVALID_SCR_MSG, NULL); Error(INVALID_SCR_MSG, NULL);
else } else
xf86unGetToken (token); xf86unGetToken (token);
} }
break; break;
@ -205,18 +213,24 @@ xf86parseLayoutSection (void)
case CONF_ADJ_BELOW: case CONF_ADJ_BELOW:
case CONF_ADJ_RELATIVE: case CONF_ADJ_RELATIVE:
token = xf86getSubToken(&(ptr->lay_comment)); token = xf86getSubToken(&(ptr->lay_comment));
if (token != STRING) if (token != STRING) {
xf86conffree(aptr);
Error(INVALID_SCR_MSG, NULL); Error(INVALID_SCR_MSG, NULL);
}
aptr->adj_refscreen = val.str; aptr->adj_refscreen = val.str;
if (aptr->adj_where == CONF_ADJ_RELATIVE) if (aptr->adj_where == CONF_ADJ_RELATIVE)
{ {
token = xf86getSubToken(&(ptr->lay_comment)); token = xf86getSubToken(&(ptr->lay_comment));
if (token != NUMBER) if (token != NUMBER) {
xf86conffree(aptr);
Error(INVALID_SCR_MSG, NULL); Error(INVALID_SCR_MSG, NULL);
}
aptr->adj_x = val.num; aptr->adj_x = val.num;
token = xf86getSubToken(&(ptr->lay_comment)); token = xf86getSubToken(&(ptr->lay_comment));
if (token != NUMBER) if (token != NUMBER) {
xf86conffree(aptr);
Error(INVALID_SCR_MSG, NULL); Error(INVALID_SCR_MSG, NULL);
}
aptr->adj_y = val.num; aptr->adj_y = val.num;
} }
break; break;
@ -225,18 +239,24 @@ xf86parseLayoutSection (void)
aptr->adj_top_str = val.str; aptr->adj_top_str = val.str;
/* bottom */ /* bottom */
if (xf86getSubToken (&(ptr->lay_comment)) != STRING) if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
xf86conffree(aptr);
Error (SCREEN_MSG, NULL); Error (SCREEN_MSG, NULL);
}
aptr->adj_bottom_str = val.str; aptr->adj_bottom_str = val.str;
/* left */ /* left */
if (xf86getSubToken (&(ptr->lay_comment)) != STRING) if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
xf86conffree(aptr);
Error (SCREEN_MSG, NULL); Error (SCREEN_MSG, NULL);
}
aptr->adj_left_str = val.str; aptr->adj_left_str = val.str;
/* right */ /* right */
if (xf86getSubToken (&(ptr->lay_comment)) != STRING) if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
xf86conffree(aptr);
Error (SCREEN_MSG, NULL); Error (SCREEN_MSG, NULL);
}
aptr->adj_right_str = val.str; aptr->adj_right_str = val.str;
} }
@ -251,8 +271,10 @@ xf86parseLayoutSection (void)
iptr = xf86confcalloc (1, sizeof (XF86ConfInputrefRec)); iptr = xf86confcalloc (1, sizeof (XF86ConfInputrefRec));
iptr->list.next = NULL; iptr->list.next = NULL;
iptr->iref_option_lst = NULL; iptr->iref_option_lst = NULL;
if (xf86getSubToken (&(ptr->lay_comment)) != STRING) if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
xf86conffree(iptr);
Error (INPUTDEV_MSG, NULL); Error (INPUTDEV_MSG, NULL);
}
iptr->iref_inputdev_str = val.str; iptr->iref_inputdev_str = val.str;
while ((token = xf86getSubToken (&(ptr->lay_comment))) == STRING) while ((token = xf86getSubToken (&(ptr->lay_comment))) == STRING)
{ {

View File

@ -186,8 +186,10 @@ xf86parsePointerSection (void)
if (val.num < 0) if (val.num < 0)
Error (ZAXISMAPPING_MSG, NULL); Error (ZAXISMAPPING_MSG, NULL);
s1 = xf86uLongToString(val.num); s1 = xf86uLongToString(val.num);
if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) {
xf86conffree(s1);
Error (ZAXISMAPPING_MSG, NULL); Error (ZAXISMAPPING_MSG, NULL);
}
s2 = xf86uLongToString(val.num); s2 = xf86uLongToString(val.num);
l = strlen(s1) + 1 + strlen(s2) + 1; l = strlen(s1) + 1 + strlen(s2) + 1;
s = xf86confmalloc(l); s = xf86confmalloc(l);