<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Erik,<div><br></div><div>The analyzer specifically complains about memory allocated by malloc here:</div><div><table class="code" style="border-collapse: collapse; width: 1189px; font-family: monospace, monospace; font-size: 13px; line-height: 1.2em; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; position: static; z-index: auto; "><tbody><tr><td class="num" id="LN196" style="width: 2.5em; padding-right: 2ex; background-color: rgb(238, 238, 238); text-align: right; font-size: 8pt; color: rgb(68, 68, 68); ">196</td><td class="line" style="padding-left: 1ex; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(204, 204, 204); white-space: pre; ">                <span class="comment" style="color: green; font-style: oblique; ">/* just the filesystems specified on the command line */</span></td></tr><tr><td class="num" id="LN197" style="width: 2.5em; padding-right: 2ex; background-color: rgb(238, 238, 238); text-align: right; font-size: 8pt; color: rgb(68, 68, 68); ">197</td><td class="line" style="padding-left: 1ex; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(204, 204, 204); white-space: pre; ">            mntbuf = <span class="mrange" style="background-color: rgb(223, 221, 243); border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(111, 157, 190); ">malloc(argc * <span class="keyword" style="color: blue; ">sizeof</span>(*mntbuf))</span>;</td></tr></tbody></table><div><br></div><div>So the call to free could be conditioned on the value of "<span style="color: rgb(0, 0, 0); font-family: Monospace, monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; ">!*argv"</span><span style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; "> as well.</span></div><div><span style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; "><br></span></div><div><span style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; ">Cheers,</span></div><div><span style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; ">Anna.</span></div><div><div>On Sep 27, 2012, at 4:21 AM, Erik Cederstrand wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Den 14/09/2012 kl. 21.15 skrev Eitan Adler <<a href="mailto:lists@eitanadler.com">lists@eitanadler.com</a>>:<br><br><blockquote type="cite">On 14 September 2012 13:54, Anna Zaks <<a href="mailto:ganna@apple.com">ganna@apple.com</a>> wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite">I think it is reasonable to expect the analyzer not to warn in this particular case.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">FWIW, I plan to fix this case. But, it would be nice to differentiate<br></blockquote><blockquote type="cite">the output from a legitimate one.<br></blockquote><br>It turns out it was a bit more complicated than this. The memory pointed to by mntbuf is allocated by getmntinfo() from FreeBSD libc (original report: <a href="http://scan.freebsd.your.org/freebsd-head/bin.df/2012-09-12-amd64/report-WwB2qk.html#EndPath">http://scan.freebsd.your.org/freebsd-head/bin.df/2012-09-12-amd64/report-WwB2qk.html#EndPath</a>). The man page for this function says: "The memory allocated by getmntinfo() cannot be free(3)'d by the application." (<a href="http://www.freebsd.org/cgi/man.cgi?query=getmntinfo">http://www.freebsd.org/cgi/man.cgi?query=getmntinfo</a>).<br><br>I believe the reason for this is that the memory is shared between calls: <a href="http://fxr.watson.org/fxr/source/gen/getmntinfo.c?v=FREEBSD-LIBC">http://fxr.watson.org/fxr/source/gen/getmntinfo.c?v=FREEBSD-LIBC</a><br><br>In this specific case, it should be OK to free the memory anyway since malloc'ed memory only lives for the duration of the application, but someone on the FreeBSD list pointed out that an alternative libc implementation might instead implement getmntinfo() with file-backed mmap, in which case we can't free it.<br><br>I'm uncertain how to proceed here, so I'd like an opinion :-)<br><br>Thanks,<br>Erik</div></blockquote></div><br></div></body></html>