N
N
Newmo2020-08-03 18:21:04
linux
Newmo, 2020-08-03 18:21:04

Why does a program crash on linux?

On Windows, the program works fine, but when I pick it up on Ubuntu, it crashes with the following error:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4c92ed]

goroutine 1 [running]:
io/ioutil.readAll.func1(0xc0000ff9c0)
        /usr/local/go/src/io/ioutil/ioutil.go:30 +0x101
panic(0x6b2e40, 0x946f90)
        /usr/local/go/src/runtime/panic.go:969 +0x166
bytes.(*Buffer).ReadFrom(0xc0000ff948, 0x0, 0x0, 0x1, 0x1, 0x672f16)
        /usr/local/go/src/bytes/buffer.go:204 +0x7d
io/ioutil.readAll(0x0, 0x0, 0x200, 0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/go/src/io/ioutil/ioutil.go:36 +0xe3
io/ioutil.ReadAll(...)
        /usr/local/go/src/io/ioutil/ioutil.go:45
main.main()
        /tmp/main.go:113 +0x6ba
exit status 2


Here is the code itself:
112    res, _ := p.Exec(js)
113		output, err := ioutil.ReadAll(res)
114		//fmt.Println(string(output))
115			if err != nil {
116				log.Panic(err)
117			}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2020-08-03
@Newmo

handle the Exec error, most likely there is an error, and res in this case is nil, so panic

res, err := p.Exec(js)
if err != nil {
   log.Panic(err)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question