staging: android: fix mem leaks in __persistent_ram_init()
authorJesper Juhl <jj@chaosbits.net>
Wed, 11 Apr 2012 20:10:20 +0000 (22:10 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 25 Apr 2012 22:25:18 +0000 (01:25 +0300)
commit260c232d113858a8b43bd8aa8c1c15c6e3db2ee2
tree27bbe7a14002b2146aefe52131acfd34127c17c2
parentf4ea770d9ec34fe9232b962f385e0700f100f3ec
staging: android: fix mem leaks in __persistent_ram_init()

If, in __persistent_ram_init(), the call to
persistent_ram_buffer_init() fails or the call to
persistent_ram_init_ecc() fails then we fail to free the memory we
allocated to 'prz' with kzalloc() - thus leaking it.

To prevent the leaks I consolidated all error exits from the function
at a 'err:' label at the end and made all error cases jump to that
label where we can then make sure we always free 'prz'. This is safe
since all the situations where the code bails out happen before 'prz'
has been stored anywhere and although we'll do a redundant kfree(NULL)
call in the case of kzalloc() itself failing that's OK since kfree()
deals gracefully with NULL pointers and I felt it was more important
to keep all error exits at a single location than to avoid that one
harmless/redundant kfree() on a error path.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Colin Cross <ccross@android.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/persistent_ram.c