mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virSysinfoParseX86BaseBoard: Free memory upfront if no board detected
If no board was detected then VIR_REALLOC_N() done at the end of the function will actually free the memory (because nborads == 0), but @boards will be set to a non-NULL pointer. This makes it unnecessary harder for a caller to see if any board was detected. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c57b205ccf
commit
ac10f838f9
@ -844,8 +844,12 @@ virSysinfoParseX86BaseBoard(const char *base,
|
|||||||
nboards--;
|
nboards--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is safe, as we can be only shrinking the memory */
|
if (nboards == 0) {
|
||||||
ignore_value(VIR_REALLOC_N(boards, nboards));
|
VIR_FREE(boards);
|
||||||
|
} else {
|
||||||
|
/* This is safe, as we can be only shrinking the memory */
|
||||||
|
ignore_value(VIR_REALLOC_N(boards, nboards));
|
||||||
|
}
|
||||||
|
|
||||||
*baseBoard = boards;
|
*baseBoard = boards;
|
||||||
*nbaseBoard = nboards;
|
*nbaseBoard = nboards;
|
||||||
|
Loading…
Reference in New Issue
Block a user