From 879fde32720d543ac6c7c7c6ca2e3b88a907a9d2 Mon Sep 17 00:00:00 2001 From: Julio Faracco Date: Wed, 7 Nov 2018 18:57:02 -0200 Subject: [PATCH] lxc: Clang is complaining about possible NULL pointer. The array "mount" inside lxc_container is not being checked before for loop. Clang syntax scan is complaining about this segmentation fault. Signed-off-by: Julio Faracco Reviewed-by: John Ferlan --- src/lxc/lxc_container.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 918194dacd..d834bf01d7 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -867,9 +867,13 @@ static int lxcContainerSetReadOnly(void) } } - if (mounts) - qsort(mounts, nmounts, sizeof(mounts[0]), - virStringSortRevCompare); + if (!mounts) { + ret = 0; + goto cleanup; + } + + qsort(mounts, nmounts, sizeof(mounts[0]), + virStringSortRevCompare); for (i = 0; i < nmounts; i++) { VIR_DEBUG("Bind readonly %s", mounts[i]); @@ -883,9 +887,7 @@ static int lxcContainerSetReadOnly(void) ret = 0; cleanup: - for (i = 0; i < nmounts; i++) - VIR_FREE(mounts[i]); - VIR_FREE(mounts); + virStringListFreeCount(mounts, nmounts); endmntent(procmnt); return ret;