* [PATCH] hw/audio/fmopl: fix segmentation fault
@ 2020-03-24 6:18 Volker Rümelin
2020-03-24 13:34 ` [PATCH-for-5.0] " Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Volker Rümelin @ 2020-03-24 6:18 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Philippe Mathieu-Daudé, QEMU
Current code allocates the memory for ENV_CURVE too late. Move
allocation to OPLOpenTable() and deallocation to OPLCloseTable().
To reproduce the bug start qemu with -soundhw adlib.
Fixes 2eea51bd01 "hw/audio/fmopl: Move ENV_CURVE to .heap to save
32KiB of .bss"
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
hw/audio/fmopl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 356d4dfbca..8a71a569fa 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -627,6 +627,7 @@ static int OPLOpenTable( void )
free(AMS_TABLE);
return 0;
}
+ ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
/* make total level table */
for (t = 0;t < EG_ENT-1 ;t++){
rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20); /* dB -> voltage */
@@ -694,6 +695,7 @@ static int OPLOpenTable( void )
static void OPLCloseTable( void )
{
+ g_free(ENV_CURVE);
free(TL_TABLE);
free(SIN_TABLE);
free(AMS_TABLE);
@@ -1090,7 +1092,6 @@ FM_OPL *OPLCreate(int clock, int rate)
OPL->clock = clock;
OPL->rate = rate;
OPL->max_ch = max_ch;
- ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
/* init grobal tables */
OPL_initialize(OPL);
/* reset chip */
@@ -1128,7 +1129,6 @@ void OPLDestroy(FM_OPL *OPL)
#endif
OPL_UnLockTable();
free(OPL);
- g_free(ENV_CURVE);
}
/* ---------- Option handlers ---------- */
--
2.16.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH-for-5.0] hw/audio/fmopl: fix segmentation fault
2020-03-24 6:18 [PATCH] hw/audio/fmopl: fix segmentation fault Volker Rümelin
@ 2020-03-24 13:34 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-03-24 13:34 UTC (permalink / raw)
To: Volker Rümelin, Gerd Hoffmann; +Cc: QEMU
On 3/24/20 7:18 AM, Volker Rümelin wrote:
> Current code allocates the memory for ENV_CURVE too late. Move
> allocation to OPLOpenTable() and deallocation to OPLCloseTable().
>
> To reproduce the bug start qemu with -soundhw adlib.
>
> Fixes 2eea51bd01 "hw/audio/fmopl: Move ENV_CURVE to .heap to save
> 32KiB of .bss"
Oops sorry, thanks for the fix!
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> ---
> hw/audio/fmopl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
> index 356d4dfbca..8a71a569fa 100644
> --- a/hw/audio/fmopl.c
> +++ b/hw/audio/fmopl.c
> @@ -627,6 +627,7 @@ static int OPLOpenTable( void )
> free(AMS_TABLE);
> return 0;
> }
> + ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
> /* make total level table */
> for (t = 0;t < EG_ENT-1 ;t++){
> rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20); /* dB -> voltage */
> @@ -694,6 +695,7 @@ static int OPLOpenTable( void )
>
> static void OPLCloseTable( void )
> {
> + g_free(ENV_CURVE);
> free(TL_TABLE);
> free(SIN_TABLE);
> free(AMS_TABLE);
> @@ -1090,7 +1092,6 @@ FM_OPL *OPLCreate(int clock, int rate)
> OPL->clock = clock;
> OPL->rate = rate;
> OPL->max_ch = max_ch;
> - ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
> /* init grobal tables */
> OPL_initialize(OPL);
> /* reset chip */
> @@ -1128,7 +1129,6 @@ void OPLDestroy(FM_OPL *OPL)
> #endif
> OPL_UnLockTable();
> free(OPL);
> - g_free(ENV_CURVE);
> }
>
> /* ---------- Option handlers ---------- */
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-24 13:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24 6:18 [PATCH] hw/audio/fmopl: fix segmentation fault Volker Rümelin
2020-03-24 13:34 ` [PATCH-for-5.0] " Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).