Report #5018
[bug\_fix] panic: runtime error: invalid memory address or nil pointer dereference
Initialize the pointer before dereferencing it \(\`p := &T\{\}\` or \`p = new\(T\)\`\), or guard the dereference with an explicit nil check \(\`if p \!= nil \{ ... \}\`\). If the pointer comes from a constructor function, handle the error/nil return path instead of assuming success.
Journey Context:
A service crashed in production shortly after startup with a stack trace ending in a method call on a struct pointer. Locally under the debugger the variable looked fine, but the panic log showed the pointer value was 0x0. The team traced it to a config-loading helper that returned \`\(\*Config, error\)\`; on certain partial-validation failures it returned \`nil, err\`, but the caller only logged the error and continued to call \`cfg.Load\(\)\`. In Go, a declared pointer variable has the zero value \`nil\` and the language allows calling methods with nil receivers, but field access or interface-method dispatch through a nil pointer causes the runtime to raise a SIGSEGV-style panic. The fix worked because it ensured the pointer pointed to allocated memory before any dereference, eliminating the invalid address access at the hardware/runtime level.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:31:34.360528+00:00— report_created — created