dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.52k stars 338 forks source link

Replace realloc with g_realloc in icon-lookup.c #1182

Closed Costinteo closed 1 year ago

Costinteo commented 1 year ago

The purpose is to avoid any failure in realloc, leading to null pointer dereferences/memory leaks. Failure in g_realloc will also terminate Dunst. @bebehei, waiting for any further suggestions/reviews. :)

bebehei commented 1 year ago

Hey @Costinteo, I've checked the code. The problems you found are fixed, but this PR will solve a fraction of the memory problems.

Why is the calloc in the same file not problematic? See here: https://github.com/dunst-project/dunst/blob/dfab9f057f89702ade5725c8247a520ab51026f4/src/icon-lookup.c#L67

Costinteo commented 1 year ago

@bebehei, following your comment, I've analysed the rest of the code base and replaced all alloc functions with their GLib counterparts. calloc calls have been specifically replaced with g_malloc followed by a memset to 0. Except for this case, where the memory was initialised anyway, in the next few lines: https://github.com/Costinteo/dunst/blob/master/src/icon-lookup.c#L130

EDIT: Just noticed there's a g_malloc0 in GLib. I'll be replacing the g_malloc + memset pairs with that, instead. EDIT2: Done. You can look through it.

fwsmit commented 1 year ago

calloc should be replaced with gmalloc0_n, not gmalloc0, so I fixed that. Thanks for the PR!