* [Qemu-devel] some questions about g_malloc in qemu @ 2011-12-15 8:10 Zhi Hui Li 2011-12-15 8:14 ` 陳韋任 ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Zhi Hui Li @ 2011-12-15 8:10 UTC (permalink / raw) To: QEMU-devel, Stefan Hajnoczi, Kevin Wolf; +Cc: zhihuili I am not sure whether it is need to check the return of g_malloc in qemu ? Thank you very much ! ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 8:10 [Qemu-devel] some questions about g_malloc in qemu Zhi Hui Li @ 2011-12-15 8:14 ` 陳韋任 2011-12-15 8:19 ` Andreas Färber 2011-12-15 8:28 ` 陳韋任 2 siblings, 0 replies; 12+ messages in thread From: 陳韋任 @ 2011-12-15 8:14 UTC (permalink / raw) To: Zhi Hui Li; +Cc: Kevin Wolf, zhihuili, QEMU-devel, Stefan Hajnoczi > I am not sure whether it is need to check the return of g_malloc in > qemu ? I think not, that's why you use g_malloc as a wrapper. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 8:10 [Qemu-devel] some questions about g_malloc in qemu Zhi Hui Li 2011-12-15 8:14 ` 陳韋任 @ 2011-12-15 8:19 ` Andreas Färber 2011-12-15 8:28 ` 陳韋任 2 siblings, 0 replies; 12+ messages in thread From: Andreas Färber @ 2011-12-15 8:19 UTC (permalink / raw) To: Zhi Hui Li; +Cc: Kevin Wolf, zhihuili, QEMU-devel, Stefan Hajnoczi Am 15.12.2011 09:10, schrieb Zhi Hui Li: > > I am not sure whether it is need to check the return of g_malloc in > qemu ? Compare the glib manual: http://developer.gnome.org/glib/2.30/glib-Memory-Allocation.html#g-malloc http://developer.gnome.org/glib/2.30/glib-Memory-Allocation.html#g-try-malloc So, g_malloc() may return NULL if the requested size is zero, and it may abort but does not return NULL due to insufficient memory available. HTH, Andreas -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 8:10 [Qemu-devel] some questions about g_malloc in qemu Zhi Hui Li 2011-12-15 8:14 ` 陳韋任 2011-12-15 8:19 ` Andreas Färber @ 2011-12-15 8:28 ` 陳韋任 2011-12-15 9:36 ` Stefan Hajnoczi 2 siblings, 1 reply; 12+ messages in thread From: 陳韋任 @ 2011-12-15 8:28 UTC (permalink / raw) To: Zhi Hui Li; +Cc: Kevin Wolf, zhihuili, QEMU-devel, Stefan Hajnoczi Hi, I found this in HACKING: Please note that NULL check for the g_malloc result is redundant and that g_malloc() call with zero size is not allowed. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 8:28 ` 陳韋任 @ 2011-12-15 9:36 ` Stefan Hajnoczi 2011-12-15 9:48 ` Zhi Hui Li 2011-12-15 10:02 ` Kevin Wolf 0 siblings, 2 replies; 12+ messages in thread From: Stefan Hajnoczi @ 2011-12-15 9:36 UTC (permalink / raw) To: 陳韋任 Cc: Kevin Wolf, Zhi Hui Li, zhihuili, Stefan Hajnoczi, QEMU-devel On Thu, Dec 15, 2011 at 04:28:28PM +0800, 陳韋任 wrote: > I found this in HACKING: > > Please note that NULL check for the g_malloc result is redundant and > that g_malloc() call with zero size is not allowed. So we have: 1. You should not request 0 bytes from g_malloc(). 2. g_malloc() does not return NULL (if you follow rule #1). There is no need to check for NULL return. Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 9:36 ` Stefan Hajnoczi @ 2011-12-15 9:48 ` Zhi Hui Li 2011-12-15 9:56 ` 陳韋任 2011-12-15 10:02 ` Kevin Wolf 1 sibling, 1 reply; 12+ messages in thread From: Zhi Hui Li @ 2011-12-15 9:48 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: QEMU-devel On 2011年12月15日 17:36, Stefan Hajnoczi wrote: > On Thu, Dec 15, 2011 at 04:28:28PM +0800, 陳韋任 wrote: >> I found this in HACKING: >> >> Please note that NULL check for the g_malloc result is redundant and >> that g_malloc() call with zero size is not allowed. > > So we have: > > 1. You should not request 0 bytes from g_malloc(). > 2. g_malloc() does not return NULL (if you follow rule #1). > > There is no need to check for NULL return. > > Stefan > > Maybe there is insufficient memory, the return is error, Do we need to check the return ? Thank you very much for your feedback! ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 9:48 ` Zhi Hui Li @ 2011-12-15 9:56 ` 陳韋任 0 siblings, 0 replies; 12+ messages in thread From: 陳韋任 @ 2011-12-15 9:56 UTC (permalink / raw) To: Zhi Hui Li; +Cc: Stefan Hajnoczi, QEMU-devel > Maybe there is insufficient memory, the return is error, > Do we need to check the return ? It'll abort if there is not enough memory. http://mail.gnome.org/archives/gtk-app-devel-list/2003-September/msg00260.html Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 9:36 ` Stefan Hajnoczi 2011-12-15 9:48 ` Zhi Hui Li @ 2011-12-15 10:02 ` Kevin Wolf 2011-12-15 10:19 ` Stefan Hajnoczi 1 sibling, 1 reply; 12+ messages in thread From: Kevin Wolf @ 2011-12-15 10:02 UTC (permalink / raw) To: Stefan Hajnoczi Cc: QEMU-devel, Zhi Hui Li, zhihuili, 陳韋任, Stefan Hajnoczi Am 15.12.2011 10:36, schrieb Stefan Hajnoczi: > On Thu, Dec 15, 2011 at 04:28:28PM +0800, 陳韋任 wrote: >> I found this in HACKING: >> >> Please note that NULL check for the g_malloc result is redundant and >> that g_malloc() call with zero size is not allowed. > > So we have: > > 1. You should not request 0 bytes from g_malloc(). I think this was related to qemu_malloc() and Anthony's sed run made it refer to g_malloc(), even though it works just fine with 0 bytes. We should probably remove this sentence. Kevin ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 10:02 ` Kevin Wolf @ 2011-12-15 10:19 ` Stefan Hajnoczi 2011-12-15 10:37 ` Max Filippov ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Stefan Hajnoczi @ 2011-12-15 10:19 UTC (permalink / raw) To: Kevin Wolf Cc: Stefan Hajnoczi, Zhi Hui Li, zhihuili, 陳韋任, QEMU-devel On Thu, Dec 15, 2011 at 11:02:39AM +0100, Kevin Wolf wrote: > Am 15.12.2011 10:36, schrieb Stefan Hajnoczi: > > On Thu, Dec 15, 2011 at 04:28:28PM +0800, 陳韋任 wrote: > >> I found this in HACKING: > >> > >> Please note that NULL check for the g_malloc result is redundant and > >> that g_malloc() call with zero size is not allowed. > > > > So we have: > > > > 1. You should not request 0 bytes from g_malloc(). > > I think this was related to qemu_malloc() and Anthony's sed run made it > refer to g_malloc(), even though it works just fine with 0 bytes. We > should probably remove this sentence. If you remove it then you can't interpret it the way I did. It's not longer possible to say that g_malloc() never returns NULL. You always have to qualify that with "unless you ask for 0 bytes". :) Stefan ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 10:19 ` Stefan Hajnoczi @ 2011-12-15 10:37 ` Max Filippov 2011-12-15 10:44 ` Kevin Wolf 2011-12-15 10:45 ` Peter Maydell 2 siblings, 0 replies; 12+ messages in thread From: Max Filippov @ 2011-12-15 10:37 UTC (permalink / raw) To: Stefan Hajnoczi Cc: Kevin Wolf, Zhi Hui Li, 陳韋任, Stefan Hajnoczi, QEMU-devel, zhihuili >> >> I found this in HACKING: >> >> >> >> Please note that NULL check for the g_malloc result is redundant and >> >> that g_malloc() call with zero size is not allowed. >> > >> > So we have: >> > >> > 1. You should not request 0 bytes from g_malloc(). >> >> I think this was related to qemu_malloc() and Anthony's sed run made it >> refer to g_malloc(), even though it works just fine with 0 bytes. We >> should probably remove this sentence. > > If you remove it then you can't interpret it the way I did. It's not > longer possible to say that g_malloc() never returns NULL. You always > have to qualify that with "unless you ask for 0 bytes". :) I have a number of ELFs that result in ELF loader making zero-size malloc. Previously I had to enable CONFIG_ZERO_MALLOC, now it just works. -- Thanks. -- Max ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 10:19 ` Stefan Hajnoczi 2011-12-15 10:37 ` Max Filippov @ 2011-12-15 10:44 ` Kevin Wolf 2011-12-15 10:45 ` Peter Maydell 2 siblings, 0 replies; 12+ messages in thread From: Kevin Wolf @ 2011-12-15 10:44 UTC (permalink / raw) To: Stefan Hajnoczi Cc: Stefan Hajnoczi, Zhi Hui Li, zhihuili, 陳韋任, QEMU-devel Am 15.12.2011 11:19, schrieb Stefan Hajnoczi: > On Thu, Dec 15, 2011 at 11:02:39AM +0100, Kevin Wolf wrote: >> Am 15.12.2011 10:36, schrieb Stefan Hajnoczi: >>> On Thu, Dec 15, 2011 at 04:28:28PM +0800, 陳韋任 wrote: >>>> I found this in HACKING: >>>> >>>> Please note that NULL check for the g_malloc result is redundant and >>>> that g_malloc() call with zero size is not allowed. >>> >>> So we have: >>> >>> 1. You should not request 0 bytes from g_malloc(). >> >> I think this was related to qemu_malloc() and Anthony's sed run made it >> refer to g_malloc(), even though it works just fine with 0 bytes. We >> should probably remove this sentence. > > If you remove it then you can't interpret it the way I did. It's not > longer possible to say that g_malloc() never returns NULL. You always > have to qualify that with "unless you ask for 0 bytes". :) Try this: "g_malloc() never returns an error". ;-) Kevin ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] some questions about g_malloc in qemu 2011-12-15 10:19 ` Stefan Hajnoczi 2011-12-15 10:37 ` Max Filippov 2011-12-15 10:44 ` Kevin Wolf @ 2011-12-15 10:45 ` Peter Maydell 2 siblings, 0 replies; 12+ messages in thread From: Peter Maydell @ 2011-12-15 10:45 UTC (permalink / raw) To: Stefan Hajnoczi Cc: Kevin Wolf, Zhi Hui Li, 陳韋任, Stefan Hajnoczi, QEMU-devel, zhihuili On 15 December 2011 10:19, Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> wrote: > On Thu, Dec 15, 2011 at 11:02:39AM +0100, Kevin Wolf wrote: >> I think this was related to qemu_malloc() and Anthony's sed run made it >> refer to g_malloc(), even though it works just fine with 0 bytes. We >> should probably remove this sentence. > > If you remove it then you can't interpret it the way I did. It's not > longer possible to say that g_malloc() never returns NULL. You always > have to qualify that with "unless you ask for 0 bytes". :) Well, we should reword it, then, because the thing it was warning about is no longer true... -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2011-12-15 10:46 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-12-15 8:10 [Qemu-devel] some questions about g_malloc in qemu Zhi Hui Li 2011-12-15 8:14 ` 陳韋任 2011-12-15 8:19 ` Andreas Färber 2011-12-15 8:28 ` 陳韋任 2011-12-15 9:36 ` Stefan Hajnoczi 2011-12-15 9:48 ` Zhi Hui Li 2011-12-15 9:56 ` 陳韋任 2011-12-15 10:02 ` Kevin Wolf 2011-12-15 10:19 ` Stefan Hajnoczi 2011-12-15 10:37 ` Max Filippov 2011-12-15 10:44 ` Kevin Wolf 2011-12-15 10:45 ` Peter Maydell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).