Skip to content
  • Igor Solodovnikov's avatar
    915a48f3
    Bug #20598261 VALGRIND: MEMORY LEAK IN MYSQL_STMT_PREPARE API · 915a48f3
    Igor Solodovnikov authored
    
    
    Memory leak was caused by prepared statement fields metadata allocated
    on MYSQL's field_alloc. field_alloc is reset by free_old_query()
    function but only if mysql->fields is not NULL. In this case memory
    was allocated by mysql_stmt_prepare() and then free_old_query() was
    called from mysql_execute() while mysql->fields is NULL. Thus
    mysql->field_alloc was reset without freeing allocated memory.
    
    Fixed by extending cli_read_metadata() function to be able to accept
    MEM_ROOT pointer. Extended function is cli_read_metadat_ex().
    cli_read_metadata() is now simple shell which uses &mysql->field_alloc
    as a parameter to cli_read_metadata_ex() . cli_read_prepare_result()
    now uses stmt->mem_root to allocate memory for fields metadata. By the
    way stmt->mem_root was used in this context before WL#7766 (commit
    03149053bf7fb93e841fd68414109b69a4413018).
    
    Reviewed-by: default avatarRafal Somla <rafal.somla@oracle.com>
    Reviewed-by: default avatarPraveen Hulakund <praveenkumar.hulakund@oracle.com>
    RB: 8156
    915a48f3
    Bug #20598261 VALGRIND: MEMORY LEAK IN MYSQL_STMT_PREPARE API
    Igor Solodovnikov authored
    
    
    Memory leak was caused by prepared statement fields metadata allocated
    on MYSQL's field_alloc. field_alloc is reset by free_old_query()
    function but only if mysql->fields is not NULL. In this case memory
    was allocated by mysql_stmt_prepare() and then free_old_query() was
    called from mysql_execute() while mysql->fields is NULL. Thus
    mysql->field_alloc was reset without freeing allocated memory.
    
    Fixed by extending cli_read_metadata() function to be able to accept
    MEM_ROOT pointer. Extended function is cli_read_metadat_ex().
    cli_read_metadata() is now simple shell which uses &mysql->field_alloc
    as a parameter to cli_read_metadata_ex() . cli_read_prepare_result()
    now uses stmt->mem_root to allocate memory for fields metadata. By the
    way stmt->mem_root was used in this context before WL#7766 (commit
    03149053bf7fb93e841fd68414109b69a4413018).
    
    Reviewed-by: default avatarRafal Somla <rafal.somla@oracle.com>
    Reviewed-by: default avatarPraveen Hulakund <praveenkumar.hulakund@oracle.com>
    RB: 8156
Loading