<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>Hi,<br>
<br>
Sean Millichamp wrote the following on 02.11.2009 18:39:</tt>
<blockquote cite="mid:1257183573.412.29.camel@localhost" type="cite">
<pre wrap=""><tt>There are some instances where asprintf() are used to construct strings
but the resulting allocated memory isn't ever free()d. This patch
(against Nagios 3.2.0) makes sure that the strings allocated by asprintf
are freed when they are no longer needed.
</tt></pre>
</blockquote>
<tt>For the single free statements I fully agree with the
implementation. But for the longer parts I would recommend another way
of implementation - I think your direction is kind of complicated, no
offense.<br>
<br>
</tt>
<pre><tt> /* generate the query */
asprintf(&api_query,"v=1&product=icinga&tinycheck=1&stableonly=1");
if(bare_update_check==FALSE)
asprintf(&api_query,"%s&version=%s%s",api_query,PROGRAM_VERSION,(api_query_opts==NULL)?"":api_query_opts);
</tt></pre>
<p><tt>rewritten to</tt></p>
<pre><tt><code>/* generate the query */
if(bare_update_check==FALSE) {
asprintf(&api_query,"%s&version=%s%s",api_query,PROGRAM_VERSION,(api_query_opts==NULL)?"":api_query_opts);
} else {
asprintf(&api_query,"v=1&product=icinga&tinycheck=1&stableonly=1");
}</code></tt></pre>
<p><tt>does the same, but does not need a second buffer and needs less
cycles as your proposal.<br>
</tt></p>
<p><tt>same for</tt></p>
<pre><tt> asprintf(&buf,"POST %s HTTP/1.0\r\n",api_path);
asprintf(&buf,"%sUser-Agent: Nagios/%s\r\n",buf,PROGRAM_VERSION);
asprintf(&buf,"%sConnection: close\r\n",buf);
asprintf(&buf,"%sHost: %s\r\n",buf,api_server);
asprintf(&buf,"%sContent-Type: application/x-www-form-urlencoded\r\n",buf);
asprintf(&buf,"%sContent-Length: %d\r\n",buf,strlen(api_query));
asprintf(&buf,"%s\r\n",buf);
asprintf(&buf,"%s%s\r\n",buf,api_query);
</tt></pre>
<p><tt>if this causes a real memory leak, put it alltogether in one
single line and buffer.</tt></p>
<pre><tt> asprintf(&buf,"POST %s HTTP/1.0\r\nUser-Agent: Nagios/%s\r\nConnection: close\r\nHost: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s\r\n",api_path, PROGRAM_VERSION, api_server, strlen(api_query), api_query);
</tt></pre>
<p><tt>if you need better reading then just reformat the string in the
code a bit.<br>
</tt></p>
<p><tt>Your opinions on that?<br>
</tt></p>
<p><tt>Kind regards,<br>
Michael</tt></p>
<pre class="moz-signature" cols="72"><tt>--
DI (FH) Michael Friedrich
<a class="moz-txt-link-abbreviated" href="mailto:michael.friedrich@univie.ac.at">michael.friedrich@univie.ac.at</a>
Tel: +43 1 4277 14359
Vienna University Computer Center
Universitaetsstrasse 7
A-1010 Vienna, Austria
</tt></pre>
</body>
</html>