3 ms·
I don't like the usage of that attribute either (but if that's their strategy, fine by me.), but I still don't see where the obvious memory leaks are. Your firs
by cremno 12y ago
I don't like the usage of that attribute either (but if that's their strategy, fine by me.), but I still don't see where the obvious memory leaks are. Your first link links to a line with a strdup() call, but the corresponding free() can be found in L168.
- revelation 12y agoSorry, I linked to line 1140, but it doesn't highlight that and can't scroll to it as it is towards the end. I did just check again and realize that the single 'a' at the strndupa means it's using alloca, which is of course similarly unportable and has a whole slew of other problems, all of them intractable (did you pass that pointer to something that will use it later on? stack overflows?). So hey, not a memory leak! Rejoice! It's just similarly broken.
- cremno 12y agoOh, I am the one that has to be sorry! I didn't check the URL, even though I am aware of that issue with cgit (no line highlighting). Yeah, using alloca() (in any form, incl. VLA) isn't good style. At least it's bounded, since filename_is_valid() checks the length. But it uses FILENAME_MAX, which could be too large for the stack.
- jacquesm 12y ago> But it uses FILENAME_MAX, which could be too large for the stack. That's extremely unlikely. This is definitely not pretty or good quality C code by any standard but let's not start spreading wrong information. The stack overflowing because you use alloc for something of FILENAME_MAX length is just as likely as a malloc call running out of memory. After all, the heap grows 'up' and the stack grows 'down'. Other than that the mechanisms are roughly (very roughly, ok) identical. The only time when you have to be extremely careful with alloca is when you use it in functions that might be called in a recursive manner. But then you're playing with fire anyway if you do not have hard upper bounds on the depth of your recursion.
- to3m 12y agoWhich operating systems does systemd support? Few that don't have gcc as their official compiler, I would have thought?
- digi_owl 12y agoLinux. Poettering has in the past stated to take the book on Linux and Unix programming, and toss the sections on Unix.
- tomegun 12y agoSimilarly broken how? Just because strdupa is not magical, does not mean it has its valid uses. In particular, the problem you allude to (knowing the scope of your memory) is something you would have to get right also if you use heap-allocated memory (unless you just leak everything of course, but I think we have established that that's not something we want to do).