top | item 3971373

(no title)

databus | 14 years ago

I see 17 mallocs and not one free!

discuss

order

JoachimSchipper|14 years ago

That's acceptable for a command-line program that will terminate quickly. It's debatable whether this is good style, but it doesn't actually hurt.

databus|14 years ago

Thanks, I was wondering if that was the case. I'm used to long running programs.

My strategy in c is as soon as I write the word "malloc" I figure out where to put the free.

mikeash|14 years ago

I agree in theory. In practice, programs evolve and code gets reused. Omitting free calls because you expect the code to exit rapidly is a recipe for disaster once you change your mind later. It's much easier to put this stuff in from the start than it is to retrofit it later.

derleth|14 years ago

> That's acceptable for a command-line program that will terminate quickly

No, it isn't; you don't know how quickly the program will terminate, in general, and it only takes one program running longer than you expect to eat a horrible amount of RAM.

leif|14 years ago

get sum valgrind up in hurrr