Bug 215752

Summary: /bin/echo utility does not free() the memory which allocated by malloc()
Product: Base System Reporter: by <by>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Works As Intended    
Severity: Affects Many People CC: maxim, ngie
Priority: ---    
Version: 10.3-RELEASE   
Hardware: Any   
OS: Any   

Description by 2017-01-04 03:10:35 UTC
Overview:
I found the bug at the time viewing the source code of /bin/echo, it uses malloc() to allocate memory, but there is no free() action takes place to free the memory allocated.

Expected Results:
I think the /bin/echo utility should free() the memory at any time terminating the process, normally or abnormally.
Comment 1 Maxim Konovalov freebsd_committer freebsd_triage 2017-01-04 10:50:50 UTC
Hello,

this is quite ok to not bother to free(3) dynamically allocated memory if the program is going to exit 20 lines of code later.  No bug here actually.
Comment 2 by 2017-01-04 16:31:49 UTC
(In reply to Maxim Konovalov from comment #1)

Hi,

I have not learned that the process termination will free the heap memory.
Does this specially on FreeBSD or any convention I need to learn?
If you can give me some tips, I will be very appreciated.

Thanks,
by
Comment 3 Maxim Konovalov freebsd_committer freebsd_triage 2017-01-04 18:27:09 UTC
Hello,

This is not specific to FreeBSD.  Upon process termination, both voluntary or involuntary, the whole address space including the heap of the process is destroyed.  So, it is quite common for simple utilities like echo(1) with short life cycle to rely on this.  I think pretty much any book of unix programming covers that.  My personal recommendation is Steven's "Advanced programming in the UNIX environment" aka APUE.

I'm going to close this ticket unless you have any concerns.

Maxim
Comment 4 by 2017-01-04 23:38:11 UTC
Hi,

Okay, I am clear now. You can close this ticket.
Thanks for your explanation. By the way, I am reading APUE book now, maybe I need investigate more about this.

by
Comment 5 Enji Cooper freebsd_committer freebsd_triage 2017-01-05 00:29:17 UTC
Closed at submitter's request.