tflog+tfsdklog: Prevent slice/map leaks when setting LoggerOpts#132
tflog+tfsdklog: Prevent slice/map leaks when setting LoggerOpts#132
Conversation
Reference: #126 Reference: #131 Since the `LoggerOpts` struct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a new `context.Context` without worrying about shared data. This change introduces a `Copy()` method for `LoggerOpts` and implements it for option modifier functions which adjust a map or slice.
|
|
||
| tflog.Trace(originalCtx, "original should be masked") | ||
| tflog.Trace(originalCtx, "new should be preserved") | ||
| tflog.Trace(newCtx, "new should be masked") |
There was a problem hiding this comment.
Is it worth using different log levels for originalCtx and newCtx in order to be able to differentiate between them in the expectedOutput?
There was a problem hiding this comment.
Sure thing -- will adjust
|
|
||
| tflog.Trace(originalCtx, "original should be masked") | ||
| tflog.Trace(originalCtx, "new should be preserved") | ||
| tflog.Trace(newCtx, "new should be masked") |
There was a problem hiding this comment.
Is it worth using different log levels for originalCtx and newCtx in order to be able to differentiate between them in the expectedOutput?
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Reference #126
Closes #131
Since the
LoggerOptsstruct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a newcontext.Contextwithout worrying about shared data.This change introduces a
Copy()method forLoggerOptsand implements it for option modifier functions which adjust a map or slice.