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