]> xenbits.xensource.com Git - xen.git/commitdiff
tools/golang: When returning pointers, actually allocate structrues
authorGeorge Dunlap <george.dunlap@cloud.com>
Fri, 19 Apr 2024 09:57:04 +0000 (10:57 +0100)
committerGeorge Dunlap <george.dunlap@cloud.com>
Wed, 24 Apr 2024 15:42:16 +0000 (16:42 +0100)
In a handful of cases, it was decided to return a pointer to a
structure rather than the plain structure itself, due to the size.
However, in these cases the structure was never allocated, leading to
a nil pointer exception when calling the relevant `fromC` method.

Allocate structures before attempting to fill them in.

Fixes: 453713b1750 ("golang/xenlight: Add host-related functionality")
Reported-by: Tobias Fitschen <tobias.fitschen@posteo.de>
Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Tested-by: Tobias Fitschen <tobias.fitschen@posteo.de>
Acked-by: Nick Rosbrook <rosbrookn@gmail.com>
tools/golang/xenlight/xenlight.go

index a45c636952520823f3c13a314e476cdbf4e1629f..d793f172e5f29c6d5c161d8941260c59e6d7c25a 100644 (file)
@@ -999,6 +999,7 @@ func (ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
                err = Error(ret)
                return
        }
+       physinfo = &Physinfo{}
        err = physinfo.fromC(&cphys)
 
        return
@@ -1010,6 +1011,7 @@ func (ctx *Context) GetVersionInfo() (info *VersionInfo, err error) {
 
        cinfo = C.libxl_get_version_info(ctx.ctx)
 
+       info = &VersionInfo{}
        err = info.fromC(cinfo)
 
        return
@@ -1027,6 +1029,7 @@ func (ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) {
                return
        }
 
+       di = &Dominfo{}
        err = di.fromC(&cdi)
 
        return