From d412d6502d1ffe92e9dd5c296ef506aa6fc93efe Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 5 Mar 2024 21:42:15 -0500 Subject: [PATCH] lang: gapi: Fix a very rare nil pointer issue This only showed up while debugging a bug I caused, but technically if we fail in Init() then we could hit this nil pointer condition. --- lang/gapi/gapi.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lang/gapi/gapi.go b/lang/gapi/gapi.go index bdae741e..78c8caf0 100644 --- a/lang/gapi/gapi.go +++ b/lang/gapi/gapi.go @@ -442,7 +442,7 @@ func (obj *GAPI) LangInit() error { // the lang always tries to load from this standard path: /metadata.yaml input := "/" + interfaces.MetadataFilename // path in remote fs - obj.lang = &lang.Lang{ + lang := &lang.Lang{ Fs: fs, FsURI: obj.InputURI, Input: input, @@ -456,9 +456,10 @@ func (obj *GAPI) LangInit() error { obj.data.Logf(Name+": "+format, v...) }, } - if err := obj.lang.Init(); err != nil { + if err := lang.Init(); err != nil { return errwrap.Wrapf(err, "can't init the lang") } + obj.lang = lang // once we can't fail, store the struct... // XXX: I'm certain I've probably got a deadlock or race somewhere here // or in lib/main.go so we'll fix it with an API fixup and rewrite soon