qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devi


From: Eric Blake
Subject: Re: [Qemu-devel] ping: [PATCH v13] block/raw-posix.c: Make physical devices usable in QEMU under Mac OS X host
Date: Tue, 2 Feb 2016 12:29:31 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

On 02/02/2016 10:28 AM, Programmingkid wrote:

>> Whats the rationale here ? Using pre-allocated fixed
>> length arrays is pretty bad practice in general, but
>> especially so for filenames
> 
> With an automatic variable there is no worry about when to release it. 

Yeah, but it comes with the downside of having to worry about exhausting
stack space (there are platforms where MAXPATHLEN is intentionally
undefined [hello, GNU Hurd]), or with the downside of arbitrary
limitations.  And at the same time, MAXPATHLEN is usually wasteful -
allocating 1k or 4k of stack to store what is typically less than 100
bytes is dumb.  Really, storing file names in fixed length arrays is
better off to avoid, and just get used to dynamic management.

> Having to decide when and where to free memory is eliminated with automatic 
> variables.

That's a crutch.  Anyone who can't properly manage dynamic memory
allocation, and sticks to only static allocation out of convenience, is
a rather lazy programmer.

> The code looks cleaner without all the g_free()'s. It also might eliminate 
> possible memory leaks.

Whether eliminating g_free() looks cleaner is subjective (I actually
find g_free cleaner than foo[MAXPATHLEN]).  And the whole point of code
review is to let others ensure you don't introduce memory leaks.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]