net: take ownership of fd in socket init functions

Today net/socket.c has no consistent policy for closing the socket file
descriptor when initialization fails.  This means we leak the file
descriptor in some cases or we could also try to close it twice.

Make error paths consistent by taking ownership of the file descriptor
and closing it on error.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
1 file changed
tree: 1b824059aa57b10bb5995e276673b9cfa0e6484b
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. roms/
  20. scripts/
  21. slirp/
  22. sysconfigs/
  23. target-alpha/
  24. target-arm/
  25. target-cris/
  26. target-i386/
  27. target-lm32/
  28. target-m68k/
  29. target-microblaze/
  30. target-mips/
  31. target-ppc/
  32. target-s390x/
  33. target-sh4/
  34. target-sparc/
  35. target-unicore32/
  36. target-xtensa/
  37. tcg/
  38. tests/
  39. trace/
  40. ui/
  41. .gitignore
  42. .gitmodules
  43. .mailmap
  44. a.out.h
  45. acl.c
  46. acl.h
  47. aes.c
  48. aes.h
  49. aio.c
  50. alpha-dis.c
  51. alpha.ld
  52. arch_init.c
  53. arch_init.h
  54. arm-dis.c
  55. arm-semi.c
  56. arm.ld
  57. async.c
  58. balloon.c
  59. balloon.h
  60. bitmap.c
  61. bitmap.h
  62. bitops.c
  63. bitops.h
  64. block-migration.c
  65. block-migration.h
  66. block.c
  67. block.h
  68. block_int.h
  69. blockdev.c
  70. blockdev.h
  71. bswap.h
  72. bt-host.c
  73. bt-host.h
  74. bt-vhci.c
  75. buffered_file.c
  76. buffered_file.h
  77. cache-utils.c
  78. cache-utils.h
  79. Changelog
  80. check-qdict.c
  81. check-qfloat.c
  82. check-qint.c
  83. check-qjson.c
  84. check-qlist.c
  85. check-qstring.c
  86. cmd.c
  87. cmd.h
  88. CODING_STYLE
  89. compatfd.c
  90. compatfd.h
  91. compiler.h
  92. config.h
  93. configure
  94. console.c
  95. console.h
  96. COPYING
  97. COPYING.LIB
  98. coroutine-gthread.c
  99. coroutine-ucontext.c
  100. coroutine-win32.c
  101. cpu-all.h
  102. cpu-common.h
  103. cpu-defs.h
  104. cpu-exec.c
  105. cpus.c
  106. cpus.h
  107. cris-dis.c
  108. cursor.c
  109. cursor_hidden.xpm
  110. cursor_left_ptr.xpm
  111. cutils.c
  112. def-helper.h
  113. device_tree.c
  114. device_tree.h
  115. dis-asm.h
  116. disas.c
  117. disas.h
  118. dma-helpers.c
  119. dma.h
  120. dyngen-exec.h
  121. elf.h
  122. envlist.c
  123. envlist.h
  124. error.c
  125. error.h
  126. error_int.h
  127. event_notifier.c
  128. event_notifier.h
  129. exec-all.h
  130. exec-memory.h
  131. exec.c
  132. gdbstub.c
  133. gdbstub.h
  134. gen-icount.h
  135. HACKING
  136. hmp-commands.hx
  137. hmp.c
  138. hmp.h
  139. host-utils.c
  140. host-utils.h
  141. hppa-dis.c
  142. hppa.ld
  143. i386-dis.c
  144. i386.ld
  145. ia64-dis.c
  146. ia64.ld
  147. input.c
  148. int128.h
  149. iohandler.c
  150. ioport-user.c
  151. ioport.c
  152. ioport.h
  153. iorange.h
  154. iov.c
  155. iov.h
  156. json-lexer.c
  157. json-lexer.h
  158. json-parser.c
  159. json-parser.h
  160. json-streamer.c
  161. json-streamer.h
  162. kvm-all.c
  163. kvm-stub.c
  164. kvm.h
  165. libfdt_env.h
  166. LICENSE
  167. linux-aio.c
  168. m68k-dis.c
  169. m68k-semi.c
  170. m68k.ld
  171. main-loop.c
  172. main-loop.h
  173. MAINTAINERS
  174. Makefile
  175. Makefile.dis
  176. Makefile.hw
  177. Makefile.objs
  178. Makefile.target
  179. Makefile.user
  180. memory.c
  181. memory.h
  182. microblaze-dis.c
  183. migration-exec.c
  184. migration-fd.c
  185. migration-tcp.c
  186. migration-unix.c
  187. migration.c
  188. migration.h
  189. mips-dis.c
  190. mips.ld
  191. module.c
  192. module.h
  193. monitor.c
  194. monitor.h
  195. nbd.c
  196. nbd.h
  197. net.c
  198. net.h
  199. notify.c
  200. notify.h
  201. os-posix.c
  202. os-win32.c
  203. osdep.c
  204. osdep.h
  205. oslib-posix.c
  206. oslib-win32.c
  207. path.c
  208. pci-ids.txt
  209. pflib.c
  210. pflib.h
  211. poison.h
  212. posix-aio-compat.c
  213. ppc-dis.c
  214. ppc.ld
  215. ppc64.ld
  216. qapi-schema-guest.json
  217. qapi-schema-test.json
  218. qapi-schema.json
  219. qbool.c
  220. qbool.h
  221. qdict-test-data.txt
  222. qdict.c
  223. qdict.h
  224. qemu-aio.h
  225. qemu-barrier.h
  226. qemu-char.c
  227. qemu-char.h
  228. qemu-common.h
  229. qemu-config.c
  230. qemu-config.h
  231. qemu-coroutine-int.h
  232. qemu-coroutine-lock.c
  233. qemu-coroutine.c
  234. qemu-coroutine.h
  235. qemu-doc.texi
  236. qemu-error.c
  237. qemu-error.h
  238. qemu-ga.c
  239. qemu-img-cmds.hx
  240. qemu-img.c
  241. qemu-img.texi
  242. qemu-io.c
  243. qemu-lock.h
  244. qemu-log.h
  245. qemu-nbd.c
  246. qemu-nbd.texi
  247. qemu-objects.h
  248. qemu-option.c
  249. qemu-option.h
  250. qemu-options.h
  251. qemu-options.hx
  252. qemu-os-posix.h
  253. qemu-os-win32.h
  254. qemu-progress.c
  255. qemu-queue.h
  256. qemu-sockets.c
  257. qemu-tech.texi
  258. qemu-thread-posix.c
  259. qemu-thread-posix.h
  260. qemu-thread-win32.c
  261. qemu-thread-win32.h
  262. qemu-thread.h
  263. qemu-timer-common.c
  264. qemu-timer.c
  265. qemu-timer.h
  266. qemu-tls.h
  267. qemu-tool.c
  268. qemu-x509.h
  269. qemu-xattr.h
  270. qemu.sasl
  271. qemu_socket.h
  272. qerror.c
  273. qerror.h
  274. qfloat.c
  275. qfloat.h
  276. qint.c
  277. qint.h
  278. qjson.c
  279. qjson.h
  280. qlist.c
  281. qlist.h
  282. qmp-commands.hx
  283. qmp.c
  284. qobject.h
  285. qstring.c
  286. qstring.h
  287. range.h
  288. readline.c
  289. readline.h
  290. README
  291. rules.mak
  292. s390-dis.c
  293. s390.ld
  294. savevm.c
  295. sh4-dis.c
  296. softmmu-semi.h
  297. softmmu_defs.h
  298. softmmu_exec.h
  299. softmmu_header.h
  300. softmmu_template.h
  301. sparc-dis.c
  302. sparc.ld
  303. sparc64.ld
  304. spice-qemu-char.c
  305. sysemu.h
  306. targphys.h
  307. tcg-runtime.c
  308. tci-dis.c
  309. tci.c
  310. test-coroutine.c
  311. test-qmp-commands.c
  312. test-qmp-input-visitor.c
  313. test-qmp-output-visitor.c
  314. thunk.c
  315. thunk.h
  316. TODO
  317. trace-events
  318. translate-all.c
  319. uboot_image.h
  320. usb-bsd.c
  321. usb-linux.c
  322. usb-redir.c
  323. usb-stub.c
  324. user-exec.c
  325. VERSION
  326. version.rc
  327. vgafont.h
  328. vl.c
  329. x86_64.ld
  330. xen-all.c
  331. xen-mapcache.c
  332. xen-mapcache.h
  333. xen-stub.c
  334. xtensa-semi.c