Skip to content

Commit

Permalink
line6: fix memory leaks in line6_init_midi()
Browse files Browse the repository at this point in the history
If the first call to line6_midibuf_init() fails we'll leak a little
bit of memory. If the second call fails we'll leak a bit more. This
happens when we return from the function and the local variable
'line6midi' goes out of scope.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jesper Juhl authored and Greg Kroah-Hartman committed Nov 27, 2011
1 parent 6f37aca commit 982d6ab
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/staging/line6/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,17 @@ int line6_init_midi(struct usb_line6 *line6)
return -ENOMEM;

err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
if (err < 0)
if (err < 0) {
kfree(line6midi);
return err;
}

err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
if (err < 0)
if (err < 0) {
kfree(line6midi->midibuf_in.buf);
kfree(line6midi);
return err;
}

line6midi->line6 = line6;
line6midi->midi_mask_transmit = 1;
Expand Down

0 comments on commit 982d6ab

Please sign in to comment.