Hello Miod,
Will certainly do, thanks for your input!
Miod Vallat wrote:
> > I recently used cppcheck on mg and I got this message:
> >
> > [macro.c:41]: (error) Memory pointed to by 'lp1' is freed twice.
> >
> > Looking at the code:
> >
> > /* free lines allocated for string arguments */
> > if (maclhead != NULL) {
> > for (lp1 = maclhead->l_fp; lp1 != maclhead; lp1 = lp2) {
> > lp2 = lp1->l_fp;
> > free(lp1);
> > }
> > free(lp1);
> > }
> >
> > What do you guys think?
>
> The
> for (a; b; c)
> d
> construct is equivalent to
> a;
> while (b) {
> d
> c
> }
>
> so we have
>
> lp1 = maclhead->l_fp;
> while (lp1 != maclhead) {
> lp2 = lp1->l_fp;
> free(lp1);
> lp1 = lp2;
> }
> free(lp1);
>
> which looks correct to me. Replacing the second free(lp1) with
> free(maclhead) should probably silence cppcheck, yet this should be
> reported as a bug to the cppcheck developers.
>
> Miod
>
# Han
--
\ / A man without religion is like a fish without a bicycle.
)\__/(
|(oO)|
\||/
Ts (OO)
+vVv------vVv----------------------------------------------------------+