mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
clh: Avoid crashing when memory hotplug is not allowed
The runtime will crash when trying to resize memory when memory hotplug is not allowed. This happens because we cannot simply set the hotplug amount to zero, leading is to not set memory hotplug at all, and later then trying to access the value of a nil pointer. Fixes: #4979 Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
9f0a57c0eb
commit
c0cb3cd4d8
@ -877,7 +877,13 @@ func (clh *cloudHypervisor) ResizeMemory(ctx context.Context, reqMemMB uint32, m
|
||||
return 0, MemoryDevice{}, err
|
||||
}
|
||||
|
||||
maxHotplugSize := utils.MemUnit(*info.Config.Memory.HotplugSize) * utils.Byte
|
||||
// HotplugSize can be nil in cases where Hotplug is not supported, as Cloud Hypervisor API
|
||||
// does *not* allow us to set 0 as the HotplugSize.
|
||||
maxHotplugSize := 0 * utils.Byte
|
||||
if info.Config.Memory.HotplugSize != nil {
|
||||
maxHotplugSize = utils.MemUnit(*info.Config.Memory.HotplugSize) * utils.Byte
|
||||
}
|
||||
|
||||
if reqMemMB > uint32(maxHotplugSize.ToMiB()) {
|
||||
reqMemMB = uint32(maxHotplugSize.ToMiB())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user