Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: echo.c: fix memory leakage

we should check the return value of calling function fir16_create(): a NULL
value means the memory allocation fails.

this patch also cleans up the error handling in function function oslec_create()

Signed-off-by: Cong Ding <dinggnu@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Cong Ding and committed by
Greg Kroah-Hartman
09024688 78855c7a

+26 -13
+26 -13
drivers/staging/echo/echo.c
··· 229 229 { 230 230 struct oslec_state *ec; 231 231 int i; 232 + const int16_t *history; 232 233 233 234 ec = kzalloc(sizeof(*ec), GFP_KERNEL); 234 235 if (!ec) ··· 239 238 ec->log2taps = top_bit(len); 240 239 ec->curr_pos = ec->taps - 1; 241 240 242 - for (i = 0; i < 2; i++) { 243 - ec->fir_taps16[i] = 244 - kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 245 - if (!ec->fir_taps16[i]) 246 - goto error_oom; 247 - } 241 + ec->fir_taps16[0] = 242 + kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 243 + if (!ec->fir_taps16[0]) 244 + goto error_oom_0; 248 245 249 - fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps); 250 - fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps); 246 + ec->fir_taps16[1] = 247 + kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 248 + if (!ec->fir_taps16[1]) 249 + goto error_oom_1; 250 + 251 + history = fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps); 252 + if (!history) 253 + goto error_state; 254 + history = fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps); 255 + if (!history) 256 + goto error_state_bg; 251 257 252 258 for (i = 0; i < 5; i++) 253 259 ec->xvtx[i] = ec->yvtx[i] = ec->xvrx[i] = ec->yvrx[i] = 0; ··· 264 256 265 257 ec->snapshot = kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 266 258 if (!ec->snapshot) 267 - goto error_oom; 259 + goto error_snap; 268 260 269 261 ec->cond_met = 0; 270 262 ec->Pstates = 0; ··· 277 269 278 270 return ec; 279 271 280 - error_oom: 281 - for (i = 0; i < 2; i++) 282 - kfree(ec->fir_taps16[i]); 283 - 272 + error_snap: 273 + fir16_free(&ec->fir_state_bg); 274 + error_state_bg: 275 + fir16_free(&ec->fir_state); 276 + error_state: 277 + kfree(ec->fir_taps16[1]); 278 + error_oom_1: 279 + kfree(ec->fir_taps16[0]); 280 + error_oom_0: 284 281 kfree(ec); 285 282 return NULL; 286 283 }