hw/audio/fmopl: fix segmentation fault
PATCH 1/1 hw/audio/fmopl: fix segmentation fault
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 <[email protected]>
--- hw/audio/fmopl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/audio/fmopl.c +2 -2
@@ -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 ---------- */
Signature · 1 line
2.16.4
Quoted 7 lines · Volker Rümelin
Current code allocates the memory for
ENV_CURVEtoo late. Move allocation toOPLOpenTable()and deallocation toOPLCloseTable().To reproduce the bug start qemu with -soundhw adlib.
Fixes
2eea51bd01"hw/audio/fmopl: MoveENV_CURVEto .heap to save 32KiB of .bss"
Oops sorry, thanks for the fix!
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 43 lines
Signed-off-by Volker Rümelin <[email protected]>--- hw/audio/fmopl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/audio/fmopl.c +2
-2@@ -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 ---------- */