mem-prealloc: fix sysconf(_SC_NPROCESSORS_ONLN) failure case.
authorJitendra Kolhe <jitendra.kolhe@hpe.com>
Tue, 21 Mar 2017 06:50:06 +0000 (02:50 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 Mar 2017 10:50:11 +0000 (11:50 +0100)
commitdfd0dcc71724b11e125f67c8710c50c41da6ee4a
tree3b04f7c11560309afd136408fc20be996f24f18a
parent30663fd26c0307e414622c7a8607fbc04f92ec14
mem-prealloc: fix sysconf(_SC_NPROCESSORS_ONLN) failure case.

This was spotted by Coverity, in case where sysconf(_SC_NPROCESSORS_ONLN)
fails and returns -1. This results in memset_num_threads getting set to -1.
Which we then pass to g_new0().
The patch replaces MAX_MEM_PREALLOC_THREAD_COUNT macro with a function call
get_memset_num_threads() to handle sysconf() failure gracefully. In case
sysconf() fails, we fall back to single threaded.

(Spotted by Coverity, CID 1372465.)

Signed-off-by: Jitendra Kolhe <jitendra.kolhe@hpe.com>
Message-Id: <1490079006-32495-1-git-send-email-jitendra.kolhe@hpe.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/oslib-posix.c