ALSA: x86: Fix memory leak in had_build_channel_allocation_map()
authorTakashi Iwai <tiwai@suse.de>
Wed, 15 Feb 2017 20:42:20 +0000 (21:42 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 16 Feb 2017 08:22:42 +0000 (09:22 +0100)
The previously allocated chmap has to be released before setting the
new one.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/x86/intel_hdmi_audio.c

index a7343f2d27303dff695bcd40aff017cf3af78f3f..5f2445389716ca93ff40b75c02b12aa505fe59ee 100644 (file)
@@ -444,11 +444,12 @@ static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)
        u8 eld_high, eld_high_mask = 0xF0;
        u8 high_msb;
 
+       kfree(intelhaddata->chmap->chmap);
+       intelhaddata->chmap->chmap = NULL;
+
        chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
-       if (!chmap) {
-               intelhaddata->chmap->chmap = NULL;
+       if (!chmap)
                return;
-       }
 
        dev_dbg(intelhaddata->dev, "eld speaker = %x\n",
                intelhaddata->eld[DRM_ELD_SPEAKER]);
@@ -493,10 +494,8 @@ static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)
                        break;
                }
        }
-       if (i >= ARRAY_SIZE(channel_allocations)) {
-               intelhaddata->chmap->chmap = NULL;
+       if (i >= ARRAY_SIZE(channel_allocations))
                kfree(chmap);
-       }
 }
 
 /*