ivi-shell: fix free in get_layers_under_surface

If a controller requests the layers under a surface that has no views attached,
Weston crashes since it tries to free the array that would be used to return the
found layers, but has not been allocated before.

Free the ppArray only if it was allocated in ivi_layout_get_layers_under_surface
before and no layers were found.

While at it, make it obvious that checking the length is an integer comparison
by comparing it to 0.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
(cherry picked from commit c56e69bc85)
This commit is contained in:
Michael Tretter 2022-09-28 12:17:29 +02:00 committed by Marius Vlad
parent 7a8392d2fe
commit 72a6929467
1 changed files with 4 additions and 5 deletions

View File

@ -1192,15 +1192,14 @@ ivi_layout_get_layers_under_surface(struct ivi_layout_surface *ivisurf,
else
length--;
}
if (length == 0) {
free(*ppArray);
*ppArray = NULL;
}
}
*pLength = length;
if (!length) {
free(*ppArray);
*ppArray = NULL;
}
return IVI_SUCCEEDED;
}