some questions about g_malloc in qemu
I am not sure whether it is need to check the return of g_malloc in qemu ?
Thank you very much !
Quoted 2 lines
I am not sure whether it is need to check the return of
g_mallocin qemu ?
I think not, that's why you use g_malloc as a wrapper.
Regards,
chenwj
Signature · 5 lines
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
Am 15.12.2011 09:10, schrieb Zhi Hui Li:
Quoted 3 lines
I am not sure whether it is need to check the return of
g_mallocin 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
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
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
Signature · 5 lines
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
Quoted 4 lines · 陳韋任
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_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
Quoted 6 lines · Stefan Hajnoczi
Quoted 4 lines · 陳韋任
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_malloc()call with zero size is not allowed.
Quoted 10 lines
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!
Quoted 2 lines
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
Signature · 5 lines
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
Am 15.12.2011 10:36, schrieb Stefan Hajnoczi:
Quoted 9 lines · 陳韋任
Quoted 4 lines
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_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
Quoted 7 lines · Kevin Wolf
Am 15.12.2011 10:36, schrieb Stefan Hajnoczi:
Quoted 6 lines · 陳韋任
Quoted 4 lines
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_malloc()call with zero size is not allowed.
Quoted 7 lines
Quoted 3 lines
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 tog_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
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_malloc()call with zero size is not allowed.So we have:
1. You should not request 0 bytes from
g_malloc().
Quoted 7 lines
Quoted 3 lines
I think this was related to
qemu_malloc()and Anthony's sed run made it refer tog_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.
Signature · 2 lines
Thanks. -- Max
Am 15.12.2011 11:19, schrieb Stefan Hajnoczi:
Quoted 12 lines · Kevin Wolf
Quoted 11 lines
Am 15.12.2011 10:36, schrieb Stefan Hajnoczi:
Quoted 9 lines · 陳韋任
Quoted 4 lines
I found this in HACKING:
Please note that NULL check for the
g_mallocresult is redundant and thatg_malloc()call with zero size is not allowed.So we have:
1. You should not request 0 bytes from
g_malloc().
Quoted 7 lines
Quoted 3 lines
I think this was related to
qemu_malloc()and Anthony's sed run made it refer tog_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
Quoted 8 lines · Stefan Hajnoczi
Quoted 3 lines · Kevin Wolf
I think this was related to
qemu_malloc()and Anthony's sed run made it refer tog_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