Merge lp:~mc-return/compiz/compiz.merge-fix-memory-leaks-in-libcompizconfig into lp:compiz/0.9.9
| Status: | Superseded | ||||
|---|---|---|---|---|---|
| Proposed branch: | lp:~mc-return/compiz/compiz.merge-fix-memory-leaks-in-libcompizconfig | ||||
| Merge into: | lp:compiz/0.9.9 | ||||
| Diff against target: |
101 lines (+32/-4) 1 file modified
compizconfig/libcompizconfig/src/main.c (+32/-4) |
||||
| To merge this branch: | bzr merge lp:~mc-return/compiz/compiz.merge-fix-memory-leaks-in-libcompizconfig | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Marco Trevisan (Treviño) | Resubmit on 2013-05-13 | ||
| Daniel van Vugt | 2012-11-08 | Needs Fixing on 2012-11-20 | |
| MC Return | Resubmit on 2012-11-19 | ||
|
Review via email:
|
|||
This proposal has been superseded by a proposal from 2013-04-02.
Commit Message
libcompizconfig memory leak fixes:
Fixed memory leak in static Bool ccsProcessSetti
Free the memory pointed to by *SectionName if (asprintf (&keyName, "-s%d_%s", cPrivate-
Fixed memory leak in static Bool ccsProcessSetti
Free the memory *sectionName is pointing to if (!newSetting) before returning FALSE.
(LP: #1076297)
Description of the Change
Note: Usually switch-case commands do not use {} brackets for the individual cases, but I kept the style already used.
Note 2: case TypeAction has no break, so it is the same as default (probably intentional).
| MC Return (mc-return) wrote : | # |
> One branch/proposal per bug please. It gets too confusing for Launchpad when
> there are multiple branches to fix a single bug.
Created a new bug report for memory leaks in libcompizconfig.
The old one showed wrong line numbers anyway, so it was outdated already.
(Info: cppcheck seems to be wrong on the third reported leak of the pointer upgradeName, so I did not fix it)
| Daniel van Vugt (vanvugt) wrote : | # |
There's a return under asprintf that needs fixing also:
char *keyName = NULL;
char *sectionName = strdup (ccsPluginGetName (ccsSettingGetP
char *iniValue = NULL;
CCSContextP
if (asprintf (&keyName, "+s%d_%s", cPrivate-
---> return FALSE;
if (ccsIniGetString (dict, sectionName, keyName, &iniValue))
{
CCSSetting *newSetting = malloc (sizeof (CCSSetting));
if (!newSetting)
{
free (sectionName);
return FALSE;
}
and also two more in ccsProcessSetti
if (!newSetting)
---> return FALSE;
...
default:
/* FIXME: cleanup */
---> return FALSE;
| MC Return (mc-return) wrote : | # |
> There's a return under asprintf that needs fixing also:
> char *keyName = NULL;
> char *sectionName = strdup (ccsPluginGetName (ccsSettingGetP
> (setting)));
> char *iniValue = NULL;
>
> CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context);
>
> if (asprintf (&keyName, "+s%d_%s", cPrivate-
> (setting)) == -1)
> ---> return FALSE;
>
> if (ccsIniGetString (dict, sectionName, keyName, &iniValue))
> {
> CCSSetting *newSetting = malloc (sizeof (CCSSetting));
>
> if (!newSetting)
> {
> free (sectionName);
> return FALSE;
> }
>
> and also two more in ccsProcessSetti
>
> if (!newSetting)
> ---> return FALSE;
> ...
> default:
> /* FIXME: cleanup */
> ---> return FALSE;
Oh - you are right. Thanks for making me aware - I did not notice it :)
Hopefully fixed in r3459.
| Daniel van Vugt (vanvugt) wrote : | # |
I think the FIXME needs to be removed and replaced with:
free (newSetting)
at least.
| MC Return (mc-return) wrote : | # |
> I think the FIXME needs to be removed and replaced with:
> free (newSetting)
> at least.
Done in r3461.
| MC Return (mc-return) wrote : | # |
Ping.
| Daniel van Vugt (vanvugt) wrote : | # |
Another FIXME in the area of the code being changed (line 4422)
/* FIXME: cleanup */
| MC Return (mc-return) wrote : | # |
> Another FIXME in the area of the code being changed (line 4422)
> default:
> /* FIXME: cleanup */
> return FALSE;
Hopefully fixed in r3462. :)
| Sam Spilsbury (smspillaz) wrote : | # |
Thats correct.
On 20/11/2012 9:24 AM, "MC Return" <email address hidden> wrote:
> The proposal to merge
> lp:~mc-return/compiz/compiz.merge-fix-memory-leaks-in-libcompizconfig into
> lp:compiz has been updated.
>
> Description changed to:
>
> Note: Usually switch-case commands do not use {} brackets for the
> individual cases, but I kept the style already used.
>
> Note 2: case TypeAction has no break, so it is the same as default
> (probably intentional).
>
> For more details, see:
>
> https:/
> --
>
> https:/
> Your team Compiz Maintainers is subscribed to branch lp:compiz.
>
| Daniel van Vugt (vanvugt) wrote : | # |
Second, third, fifth and sixth blocks are missing two frees each:
free (keyName);
free (iniValue);
So that's two frees missing twice in each function = 4 frees.
Sorry I didn't notice before.
I recommend a single return statement per function to simplify memory management and easily avoid leaks of any sort:
Bool ret = FALSE;
void *p1 = NULL;
void *p2 = NULL;
...
if (error)
goto cleanup;
...
if (some other error)
goto cleanup;
...
ret = TRUE;
cleanup:
free (p1);
free (p2);
return ret;
free() is safe to use with NULL. But for other resource types you'd just use "if (r != INVALID) FreeR(r)".
| Sam Spilsbury (smspillaz) wrote : | # |
Avoid using goto please.
Use a dedicated cleanup function.
void freeFunctionData (Foo *, Bar *)
{
free (foo);
barDestroy (bar);
}
On 20/11/2012 6:29 PM, "Daniel van Vugt" <email address hidden>
wrote:
> Review: Needs Fixing
>
> Second, third, fifth and sixth blocks are missing two frees each:
> free (keyName);
> free (iniValue);
> So that's two frees missing twice in each function = 4 frees.
>
> Sorry I didn't notice before.
>
> I recommend a single return statement per function to simplify memory
> management and easily avoid leaks of any sort:
>
> Bool ret = FALSE;
> void *p1 = NULL;
> void *p2 = NULL;
> ...
> if (error)
> goto cleanup;
> ...
> if (some other error)
> goto cleanup;
> ...
> ret = TRUE;
> cleanup:
> free (p1);
> free (p2);
> return ret;
>
> free() is safe to use with NULL. But for other resource types you'd just
> use "if (r != INVALID) FreeR(r)".
> --
>
> https:/
> Your team Compiz Maintainers is subscribed to branch lp:compiz.
>
| Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Could you please resubmit this for 0.9.9 as well?
Thanks.
| MC Return (mc-return) wrote : | # |
@3v1nO:
I could do that, but this is not the only important fix that went into 0.9.10-dev.
It would mean a lot of non-exciting work and would cost a lot of time to backport everything important to 0.9.9...
I am sure I do not want to do that unpaid in my free time...
The best solution would be to make current 0.9.10-dev the 0.9.9.2 release.
Unmerged revisions
- 3467. By MC Return on 2013-04-01
-
Merged latest lp:compiz
- 3466. By MC Return on 2013-04-01
-
Hopefully fixed all remaining leaks
- 3465. By MC Return on 2013-02-20
-
Merged latest lp:compiz
- 3464. By MC Return on 2013-02-02
-
Merged latest lp:compiz
- 3463. By MC Return on 2012-11-19
-
Added forgotten brackets
- 3462. By MC Return on 2012-11-19
-
Free newSetting and sectionName in the case TypeAction and default
- 3461. By MC Return on 2012-11-12
-
Also free (newSetting) by default if other cases do not match
- 3460. By MC Return on 2012-11-09
-
Merged latest lp:compiz
- 3459. By MC Return on 2012-11-09
-
Hopefully fixed all remaining potential memory leaks caused by sectionName
- 3458. By MC Return on 2012-11-08
-
Fixed memory leak in static Bool ccsProcessSetti
ngMinus (...)
Free the memory pointed to by *SectionName if (asprintf (&keyName, "-s%d_%s", cPrivate->screenNum, ccsSettingGetName (setting)) == -1) also


One branch/proposal per bug please. It gets too confusing for Launchpad when there are multiple branches to fix a single bug.