@@ -913,12 +913,16 @@ static void setup_key_functions(register MI_KEYDEF *keyinfo)
913913
914914uint mi_state_info_write (File file , MI_STATE_INFO * state , uint pWrite )
915915{
916- uchar buff [MI_STATE_INFO_SIZE + MI_STATE_EXTRA_SIZE ];
917- uchar * ptr = buff ;
916+ uchar * buff , * ptr ;
918917 uint i , keys = (uint ) state -> header .keys ,
919- key_blocks = state -> header .max_block_size_index ;
918+ key_blocks = state -> header .max_block_size_index ,
919+ key_parts = mi_uint2korr (state -> header .key_parts );
920+ int res ;
920921 DBUG_ENTER ("mi_state_info_write" );
921922
923+ buff = my_alloca (MI_STATE_INFO_SIZE + MI_STATE_EXTRA_SIZE (keys , key_parts ));
924+
925+ ptr = buff ;
922926 memcpy (ptr , & state -> header , sizeof (state -> header ));
923927 ptr += sizeof (state -> header );
924928
@@ -952,7 +956,6 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite)
952956 }
953957 if (pWrite & 2 ) /* From isamchk */
954958 {
955- uint key_parts = mi_uint2korr (state -> header .key_parts );
956959 mi_int4store (ptr ,state -> sec_index_changed ); ptr += 4 ;
957960 mi_int4store (ptr ,state -> sec_index_used ); ptr += 4 ;
958961 mi_int4store (ptr ,state -> version ); ptr += 4 ;
@@ -968,10 +971,13 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite)
968971 }
969972
970973 if (pWrite & 1 )
971- DBUG_RETURN (mysql_file_pwrite (file , buff , (size_t ) (ptr - buff ), 0L ,
972- MYF (MY_NABP | MY_THREADSAFE )) != 0 );
973- DBUG_RETURN (mysql_file_write (file , buff , (size_t ) (ptr - buff ),
974- MYF (MY_NABP )) != 0 );
974+ res = mysql_file_pwrite (file , buff , (size_t ) (ptr - buff ), 0L ,
975+ MYF (MY_NABP | MY_THREADSAFE )) != 0 ;
976+ else
977+ res = mysql_file_write (file , buff , (size_t ) (ptr - buff ),
978+ MYF (MY_NABP )) != 0 ;
979+ my_afree (buff );
980+ DBUG_RETURN (res );
975981}
976982
977983
@@ -1040,20 +1046,24 @@ uchar *mi_state_info_read(uchar *ptr, MI_STATE_INFO *state)
10401046
10411047uint mi_state_info_read_dsk (File file , MI_STATE_INFO * state , my_bool pRead )
10421048{
1043- uchar buff [ MI_STATE_INFO_SIZE + MI_STATE_EXTRA_SIZE ] ;
1049+ uchar * buff = my_alloca ( state -> state_length ) ;
10441050
10451051 if (!myisam_single_user )
10461052 {
10471053 if (pRead )
10481054 {
10491055 if (mysql_file_pread (file , buff , state -> state_length , 0L , MYF (MY_NABP )))
1050- return 1 ;
1056+ goto err ;
10511057 }
10521058 else if (mysql_file_read (file , buff , state -> state_length , MYF (MY_NABP )))
1053- return 1 ;
1059+ goto err ;
10541060 mi_state_info_read (buff , state );
10551061 }
1062+ my_afree (buff );
10561063 return 0 ;
1064+ err :
1065+ my_afree (buff );
1066+ return 1 ;
10571067}
10581068
10591069
0 commit comments