Eduardo Habkost <ehabk...@redhat.com> writes: > On Thu, May 10, 2018 at 06:57:32PM +0200, Paolo Bonzini wrote: > [...] >> > - machine->device_memory = g_malloc(sizeof(*machine->device_memory)); >> > + machine->device_memory = g_malloc0(sizeof(*machine->device_memory)); >> >> g_new0 since you are at it? :) > > Nice suggestion, but this was already merged. > > I think we have a Coccinelle script that should detect this?
Closest match is commit message b45c03f585e, referred to last in commit bdd81addf40 (both predate scripts/coccinelle/). However, that script only rewrites patterns involving sizeof(T), such as g_malloc(sizeof(T) * n) -> g_new(T, n) because those are obvious improvements. It doesn't rewrite patterns like T *v = g_malloc(sizeof(*v)) -> T *v = g_new(T, 1) because whether those are improvements is debatable. Feel free to apply them wherever you think they are enough of an improvement to be worth the churn. But I wouldn't apply them tree-write without rough consensus "this is what we want going forward".