ALSA: usb-audio: fix memory leak on cval
authorColin Ian King <colin.king@canonical.com>
Tue, 27 Mar 2018 14:30:01 +0000 (15:30 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 27 Mar 2018 15:45:33 +0000 (17:45 +0200)
With the current exit return path of the ctl_info allocation failure
cval is not being freed resulting in a memory leak. Fix this by kfree'ing
it on the return.

Detected by CoverityScan, CID#1466878 ("Resource Leak")

Fixes: 21e9b3e931f7 ("ALSA: usb-audio: fix uac control query argument")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/mixer.c

index 04dab6f655356e9b62036c8e39d3cef97417eac4..301ad61ed4267f28476af340325ae5173a12d2ad 100644 (file)
@@ -1365,8 +1365,10 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
        cval->cmask = ctl_mask;
 
        ctl_info = get_feature_control_info(control);
-       if (!ctl_info)
+       if (!ctl_info) {
+               kfree(cval);
                return;
+       }
        if (state->mixer->protocol == UAC_VERSION_1)
                cval->val_type = ctl_info->type;
        else /* UAC_VERSION_2 */