{"comment":{"position":null,"created_at":"2011-10-25T18:12:13Z","body":"On 25 October 2011 16:01, Edd Barrett\n<reply@reply.github.com>\nwrote:\n> On Tue, Oct 25, 2011 at 10:43:06AM -0700, Christiano F. Haesbaert wrote:\n>> Why heap alloc this ?\n>\n> How would you do it? I am trying to avoid the case where the fields can\n> be either statically/dynamically allocated. Because, if you wanted to\n> free this, how would you know if it was stack (or global) or heap allocated and thus if you should free the buffer?\n>\n\nYou shouldn't free it, it's responsability of the caller, but then, we\ndon't even have a caller, it's a global state.\n\n\n>> You also have a memory leak if the user specified -f.\n>\n> The reference to the buffer is never lost and memory consumption does\n> not continually increase. Some would say this is not a leak.\n>\n\nI beg to disagree, the pointer is lost, so it's a leak. If you free it\nbefore reassigning, I'm ok.\nBut then I don't see any point in heap allocing something which is\nkept in a global state and can only come from a constant define or\nfrom argv[].\n\n> But strictly speaking, the buffer is not freed, you are right. But\n> then *nothing* is freed when you exit due to errors either.\n>\n> I am not sure what the correct thing to do is. In my other project I\n> never used err/errx, and just returned an error state which eventually\n> frees *everything* that was ever heap allocated. However, I rarely see\n> this in bsd code.\n\nSure when you call err/errx/exit there is no problem, everything gets freed.\nThe thing is that you *lose* a pointer, you lose the reference for\nsomething which is malloced, and that is wrong.\n\n>\n> Thoughts?\n>\n\nPlease don't get me wrong, I'm not bitching, remember when I wanted to\nhave df_state heap alloced so I didn't need to use the '.' instead of\nthe '->' ? and you said people would raise eyebrowns ? This is the\nsame thing, plus the leak.\n\nAlso have in mind that having a magic_file in df_state is wrong, since\nwe'll need to support multiple magic_files, as the current file does:\n\nfile -f /etc/magic:mymagic:/etc/balbalblab and so on.","line":null,"commit_id":"1ffde1bb0c708374079a6e9b22252c93e5b39167","updated_at":"2011-10-25T18:12:13Z","url":"https://api.github.com/repos/vext01/libdefile/comments/673939","id":673939,"path":null,"user":{"gravatar_id":"d523ee160d1dca8aa31bc602d1c900d4","avatar_url":"https://secure.gravatar.com/avatar/d523ee160d1dca8aa31bc602d1c900d4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/haesbaert","id":204048,"login":"haesbaert"}},"legacy":{"commit":"1ffde1bb0c708374079a6e9b22252c93e5b39167","comment_id":673939}}