astrand / xclip

Command line interface to the X11 clipboard
GNU General Public License v2.0
1.03k stars 73 forks source link

fix segfault on conversion error #117

Open rogpeppe opened 3 years ago

rogpeppe commented 3 years ago

When I copy some text from a github commit inside Chrome, the selection cannot be converted to text. When I run xclip -o with that selection in the paste buffer, I get a segmentation fault because free is being called with an invalid argument (presumably because xcout isn't setting the sel_buf pointer correctly on error).

% xclip -o
1587474: signal: sys: segmentation violation (core dumped)

To fix this, remove the call to free in the error case, as it isn't really necessary anyway as the program is about to exit.

When the free call is removed, xclip prints this error instead of seg-faulting:

xclip: Error: 'Chromium clipboard' (0x1c00024) cannot convert PRIMARY selection to target 'STRING'