semantic: 0.978 device: 0.976 socket: 0.975 assembly: 0.975 other: 0.974 graphic: 0.973 mistranslation: 0.965 KVM: 0.964 network: 0.960 instruction: 0.960 vnc: 0.947 boot: 0.931 device_add usb-hub causes segfault in qemu-1.0 When calling the command (qemu) device_add usb-hub,bus=usb.0,port=4 qemu replies Error: usb port 4 (bus usb.0) not found (in use?) Then qemu crashes with a segfault: [ 1546.177627] qemu-system-x86[1710]: segfault at 0 ip b75d3f8b sp bfddb0b0 error 6 in qemu-system-x86_64[b7488000+2e2000] Maybe it might be related to the docs/usb2.txt where UHCI has only 2 ports. But a mistake in the port number should not cause qemu to crash Commit f462141f18ffdd75847f6459ef83d90b831d12c0 introduced clean up code when usb_qdev_init() fails. Unfortunately it calls .handle_destroy() when .init() was never invoked or failed. This can lead to crashes when .handle_destroy() tries to clean up things that were never initialized. This patch is careful to undo only those steps that completed along the usb_qdev_init() code path. It's not as pretty as the unified error handling in f462141f18ffdd75847f6459ef83d90b831d12c0 but it's necessary. Signed-off-by: Stefan Hajnoczi