mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-21 15:57:49 +00:00
Fix implicit memory aliasing in for loop
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
1b16b341dd
commit
709e27bf4b
@ -34,6 +34,7 @@ var _ oci.SpecModifier = (*fromCDISpec)(nil)
|
||||
// Modify applies the mofiications defined by the raw CDI spec to the incomming OCI spec.
|
||||
func (m fromCDISpec) Modify(spec *specs.Spec) error {
|
||||
for _, device := range m.cdiSpec.Devices {
|
||||
device := device
|
||||
cdiDevice := cdi.Device{
|
||||
Device: &device,
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ func (m nvidiaContainerRuntimeHookRemover) Modify(spec *specs.Spec) error {
|
||||
var newPrestart []specs.Hook
|
||||
|
||||
for _, hook := range spec.Hooks.Prestart {
|
||||
hook := hook
|
||||
if isNVIDIAContainerRuntimeHook(&hook) {
|
||||
m.logger.Debugf("Removing hook %v", hook)
|
||||
continue
|
||||
|
@ -48,6 +48,7 @@ func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
||||
// If an NVIDIA Container Runtime Hook already exists, we don't make any modifications to the spec.
|
||||
if spec.Hooks != nil {
|
||||
for _, hook := range spec.Hooks.Prestart {
|
||||
hook := hook
|
||||
if isNVIDIAContainerRuntimeHook(&hook) {
|
||||
m.logger.Infof("Existing nvidia prestart hook (%v) found in OCI spec", hook.Path)
|
||||
return nil
|
||||
|
@ -150,6 +150,8 @@ func TestAddHookModifier(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
logHook.Reset()
|
||||
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
|
@ -70,6 +70,7 @@ func TestNewMountSpecFromLine(t *testing.T) {
|
||||
|
||||
for i, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("test case %d", i), func(t *testing.T) {
|
||||
tc := tc
|
||||
target, err := NewMountSpecFromLine(tc.line)
|
||||
if tc.expectedError != nil {
|
||||
require.Error(t, err)
|
||||
|
@ -39,6 +39,7 @@ func (d dedupe) Transform(spec *specs.Spec) error {
|
||||
}
|
||||
var updatedDevices []specs.Device
|
||||
for _, device := range spec.Devices {
|
||||
device := device
|
||||
if err := d.transformEdits(&device.ContainerEdits); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ func mergeDeviceSpecs(deviceSpecs []specs.Device, mergedDeviceName string) (*spe
|
||||
mergedEdits := edits.NewContainerEdits()
|
||||
|
||||
for _, d := range deviceSpecs {
|
||||
d := d
|
||||
edit := cdi.ContainerEdits{
|
||||
ContainerEdits: &d.ContainerEdits,
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ func (r remove) Transform(spec *specs.Spec) error {
|
||||
}
|
||||
|
||||
for _, device := range spec.Devices {
|
||||
device := device
|
||||
if err := r.transformEdits(&device.ContainerEdits); err != nil {
|
||||
return fmt.Errorf("failed to remove edits from device %q: %w", device.Name, err)
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ func (t rootTransformer) Transform(spec *specs.Spec) error {
|
||||
}
|
||||
|
||||
for _, d := range spec.Devices {
|
||||
d := d
|
||||
if err := t.applyToEdits(&d.ContainerEdits); err != nil {
|
||||
return fmt.Errorf("failed to apply root transform to device %s: %w", d.Name, err)
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ func (d sorter) Transform(spec *specs.Spec) error {
|
||||
}
|
||||
var updatedDevices []specs.Device
|
||||
for _, device := range spec.Devices {
|
||||
device := device
|
||||
if err := d.transformEdits(&device.ContainerEdits); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -235,6 +235,8 @@ func TestUpdateConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
o := &options{
|
||||
Options: container.Options{
|
||||
RuntimeName: tc.runtimeName,
|
||||
@ -361,6 +363,7 @@ func TestRevertConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
o := &options{}
|
||||
err := o.RevertConfig(&tc.config)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user