Segfault in PCBnew while copying  plane - KDE (lp:#1800648)

[Original report](https://bugs.launchpad.net/bugs/1800648) created by **Sebastian (herostrat)**
```
Unfortunately I cannot share my PCB.

Segfault is reproducible in my case:

1) Mark plane
2) Strg+C
3) Click two times in the area
-> crash

I will append a strace.
I will also try if it works in the nightly and report it here.

Application: kicad
Version: 5.0.1-33cea8e~68~ubuntu18.04.1, release build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1
(+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-38-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.65.1
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.58.0
    Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

---------------------------

write(2, "The program 'kicad' received an "..., 563The program 'kicad'
received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 89910 error_code 3 request_code 18 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error()
function.)
) = 563
munmap(0x7fa65b64f000, 360448)          = 0
munmap(0x7fa66000a000, 901120)          = 0
getpid()                                = 15464
openat(AT_FDCWD, "/home/sebastian/.config/kicad/pcbnew943DiM",
O_RDWR|O_CREAT|O_EXCL, 0600) = 9
stat("/home/sebastian/.config/kicad/pcbnew", {st_mode=S_IFREG|0664,
st_size=19731, ...}) = 0
chmod("/home/sebastian/.config/kicad/pcbnew943DiM", 0100664) = 0
write(9, "Color4DPCBLayer_F.Cu=rgb(132, 0,"..., 19731) = 19731
close(9)                                = 0
stat("/home/sebastian/.config/kicad/pcbnew", {st_mode=S_IFREG|0664,
st_size=19731, ...}) = 0
unlink("/home/sebastian/.config/kicad/pcbnew") = 0
rename("/home/sebastian/.config/kicad/pcbnew943DiM",
"/home/sebastian/.config/kicad/pcbnew") = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x5647c079f0a0}
---
+++ killed by SIGSEGV (core dumped) +++
[1]    15462 segmentation fault (core dumped)  strace kicad

---------------------------

Running it with the suggested sync parameter:
It did not crash as described in the initial report, but after I Strg+V it.

recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=8,
events=POLLIN|POLLPRI}], 3, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="&\3\2\0\33\n\0\10", iov_len=8}, {iov_base=NULL,
iov_len=0}, {iov_base="", iov_len=0}], 3) = 8
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\1\213\33\0\0\0\0n\1\0\0\0\0\0\0\324\n)\2T\3\f\2\20\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="+\3\1\0", iov_len=4}, {iov_base=NULL, iov_len=0},
{iov_base="", iov_len=0}], 3) = 4
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\2\214\33\0\0\0\0\34\n\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="(\3\4\0\33\n\0\10n\1\0\0$\0k\0", iov_len=16},
{iov_base=NULL, iov_len=0}, {iov_base="", iov_len=0}], 3) = 16
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\1\215\33\0\0\0\0\364.\204\2\244\7\210\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="+\3\1\0", iov_len=4}, {iov_base=NULL, iov_len=0},
{iov_base="", iov_len=0}], 3) = 4
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\2\216\33\0\0\0\0\34\n\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="(\3\4\0\33\n\0\10n\1\0\0$\0k\0", iov_len=16},
{iov_base=NULL, iov_len=0}, {iov_base="", iov_len=0}], 3) = 16
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\1\217\33\0\0\0\0\364.\204\2\244\7\210\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="+\3\1\0", iov_len=4}, {iov_base=NULL, iov_len=0},
{iov_base="", iov_len=0}], 3) = 4
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\2\220\33\0\0\0\0\34\n\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="&\3\2\0\33\n\0\10", iov_len=8}, {iov_base=NULL,
iov_len=0}, {iov_base="", iov_len=0}], 3) = 8
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\1\221\33\0\0\0\0n\1\0\0\0\0\0\0\324\n)\2T\3\f\2\20\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3, [{iov_base="+\3\1\0", iov_len=4}, {iov_base=NULL, iov_len=0},
{iov_base="", iov_len=0}], 3) = 4
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\2\222\33\0\0\0\0\34\n\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
recvmsg(3, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily
unavailable)
poll([{fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=8,
events=POLLIN|POLLPRI}], 3, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLOUT}])
writev(3,
[{iov_base="\22\0\0\0\7\0\1\0\r\0\200\3L\1\0\0\210\1\0\0\10\6\1\0\0\0\4\0",
iov_len=28}, {iov_base="(kicad_pcb (version 20171130) (h"...,
iov_len=262144}, {iov_base="", iov_len=0}], 3) = 262172
poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3,
revents=POLLIN|POLLOUT}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\0\3\223\33\r\0\200\3\0\0\22\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
writev(3, [{iov_base="+\0\1\0", iov_len=4}, {iov_base=NULL, iov_len=0},
{iov_base="", iov_len=0}], 3) = 4
poll([{fd=3, events=POLLIN}], 1, -1)    = 1 ([{fd=3, revents=POLLIN}])
recvmsg(3, {msg_name=NULL, msg_namelen=0,
msg_iov=[{iov_base="\1\2\224\33\0\0\0\0\34\n\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 32
openat(AT_FDCWD, "/usr/share/X11/XErrorDB", O_RDONLY) = 9
fstat(9, {st_mode=S_IFREG|0644, st_size=42077, ...}) = 0
read(9, "!\n! Copyright 1993, 1995, 1998  "..., 42077) = 42077
close(9)                                = 0
write(2, "The program 'kicad' received an "..., 564The program 'kicad'
received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 203667 error_code 3 request_code 18 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error()
function.)
) = 564
munmap(0x7f200804a000, 360448)          = 0
munmap(0x7f20080a2000, 901120)          = 0
getpid()                                = 15717
openat(AT_FDCWD, "/home/sebastian/.config/kicad/pcbnewNAkqXb",
O_RDWR|O_CREAT|O_EXCL, 0600) = 9
stat("/home/sebastian/.config/kicad/pcbnew", {st_mode=S_IFREG|0664,
st_size=19731, ...}) = 0
chmod("/home/sebastian/.config/kicad/pcbnewNAkqXb", 0100664) = 0
write(9, "Color4DPCBLayer_F.Cu=rgb(132, 0,"..., 19731) = 19731
close(9)                                = 0
stat("/home/sebastian/.config/kicad/pcbnew", {st_mode=S_IFREG|0664,
st_size=19731, ...}) = 0
unlink("/home/sebastian/.config/kicad/pcbnew") = 0
rename("/home/sebastian/.config/kicad/pcbnewNAkqXb",
"/home/sebastian/.config/kicad/pcbnew") = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x55810b3bc0a0}
---
+++ killed by SIGSEGV (core dumped) +++
[1]    15715 segmentation fault (core dumped)  strace kicad --sync


I have no idea if the strace part is enough.
Please let me know if you need more informations.
```

Story points: 6.0