es-ude / es-ude/OnDeviceTraining
layer: softmaxInitConfig leaves ownsQuantizations indeterminate (struct-field-growth class)
- Dominant language
- C
- Stars
- 1
- Forks
- 3
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 8
Description
Follow-up from BFP epic PR6 (#439, Task-4 review deferred minor 6 — pre-existing, surfaced not introduced).
## The gap
`softmaxInitConfig` (`src/layer/Softmax.c:16` @ d9b46097) initializes `forwardMath`, `propLossMath`, `outputQ`, `propLossQ` and `bfpExpShiftRounding` — but never assigns `ownsQuantizations` (`src/layer/include/Softmax.h:15`). Its siblings all do (`Dropout.c:40`, `GroupNorm.c:39`, `LayerNorm.c:38` set `= false`); Softmax is the odd one out.
## Failure scenario
A direct caller of the public `softmaxInitConfig` who stack-allocates the `softmaxConfig_t` without zero-init gets an indeterminate `ownsQuantizations`. If that layer later goes through `freeSoftmaxLayer` (`SoftmaxApi.c:85`), a truthy garbage value triggers `freeQuantization(outputQ/propLossQ)` on caller-owned quantizations — an invalid/double free.
Not reachable in-repo today: both userApi factories (`softmaxLayerInit`/`softmaxLayerInitOwning`) overwrite the flag right after the call, and no in-repo code calls `softmaxInitConfig` directly with a non-zeroed struct. This is the struct-field-growth hazard class (a field added to the struct without sweeping every field-assigning site).
## Scope
- `softmaxInitConfig` sets `ownsQuantizations = false` (one line, mirrors the norm/Dropout siblings).
- Sweep the remaining `*InitConfig` functions against their struct's `ownsQuantizations` field for the same omission (Relu/pools/Linear/Conv family) and fix any further stragglers in the same PR.
- Regression pin: a death-/unit-test proving a `softmaxInitConfig`-initialized config is safe to route through `freeSoftmaxLayer` without touching the caller's quantizations.
Part of the #410 epic hygiene trail.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Contributor guide
Research direction
Start in src/layer/Softmax.c at softmaxInitConfig and compare it with src/layer/include/Softmax.h plus the sibling initializers in Dropout.c, GroupNorm.c, and LayerNorm.c. Sweep the remaining *InitConfig functions for ownsQuantizations omissions, then run the relevant layer tests or add the requested death/unit regression. Done means Softmax initialization sets the flag false, other stragglers are fixed, and caller-owned quantizations are not freed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100