Skip to content

Commit e6169a8

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPICA: Fix memory leak if acpi_ps_get_next_field() fails
ACPICA commit 1280045754264841b119a5ede96cd005bc09b5a7 If acpi_ps_get_next_field() fails, the previously created field list needs to be properly disposed before returning the status code. Link: acpica/acpica@12800457 Signed-off-by: Armin Wolf <[email protected]> [ rjw: Rename local variable to avoid compiler confusion ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5accb26 commit e6169a8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

drivers/acpi/acpica/psargs.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
2525
static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
2626
*parser_state);
2727

28+
static void acpi_ps_free_field_list(union acpi_parse_object *start);
29+
2830
/*******************************************************************************
2931
*
3032
* FUNCTION: acpi_ps_get_next_package_length
@@ -683,6 +685,39 @@ static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
683685
return_PTR(field);
684686
}
685687

688+
/*******************************************************************************
689+
*
690+
* FUNCTION: acpi_ps_free_field_list
691+
*
692+
* PARAMETERS: start - First Op in field list
693+
*
694+
* RETURN: None.
695+
*
696+
* DESCRIPTION: Free all Op objects inside a field list.
697+
*
698+
******************************************************************************/
699+
700+
static void acpi_ps_free_field_list(union acpi_parse_object *start)
701+
{
702+
union acpi_parse_object *cur = start;
703+
union acpi_parse_object *next;
704+
union acpi_parse_object *arg;
705+
706+
while (cur) {
707+
next = cur->common.next;
708+
709+
/* AML_INT_CONNECTION_OP can have a single argument */
710+
711+
arg = acpi_ps_get_arg(cur, 0);
712+
if (arg) {
713+
acpi_ps_free_op(arg);
714+
}
715+
716+
acpi_ps_free_op(cur);
717+
cur = next;
718+
}
719+
}
720+
686721
/*******************************************************************************
687722
*
688723
* FUNCTION: acpi_ps_get_next_arg
@@ -751,6 +786,10 @@ acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
751786
while (parser_state->aml < parser_state->pkg_end) {
752787
field = acpi_ps_get_next_field(parser_state);
753788
if (!field) {
789+
if (arg) {
790+
acpi_ps_free_field_list(arg);
791+
}
792+
754793
return_ACPI_STATUS(AE_NO_MEMORY);
755794
}
756795

0 commit comments

Comments
 (0)