--- log.cc.orig	2012-06-08 16:36:34.007231363 -0400
+++ log.cc	2012-06-08 16:36:36.218354938 -0400
@@ -1838,6 +1838,7 @@
 {
   int error= 0;
   DBUG_ENTER("binlog_commit");
+  thd->binlog_setup_trx_data();
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
 
@@ -1894,6 +1895,7 @@
 {
   DBUG_ENTER("binlog_rollback");
   int error= 0;
+  thd->binlog_setup_trx_data();
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
 
@@ -4620,7 +4622,7 @@
   return
     ((thd->is_current_stmt_binlog_format_row() ||
      thd->variables.binlog_direct_non_trans_update) ? is_transactional :
-     (is_transactional || !cache_mngr->trx_cache.empty()));
+     (is_transactional || (cache_mngr && !cache_mngr->trx_cache.empty())));
 }
 
 /**
@@ -4846,6 +4848,7 @@
   if (binlog_table_maps == 0)
     binlog_start_trans_and_stmt();
 
+  this->binlog_setup_trx_data();
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(this, binlog_hton);
 
@@ -4941,6 +4944,7 @@
 {
   DBUG_ENTER("MYSQL_BIN_LOG::remove_pending_rows_event");
 
+  thd->binlog_setup_trx_data();
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
 
@@ -4978,6 +4982,7 @@
   DBUG_PRINT("enter", ("event: 0x%lx", (long) event));
 
   int error= 0;
+  thd->binlog_setup_trx_data();
   binlog_cache_mngr *const cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
 
@@ -7422,6 +7427,7 @@
   int err;
   DBUG_ENTER("TC_LOG_BINLOG::log_and_order");
 
+  thd->binlog_setup_trx_data();
   binlog_cache_mngr *cache_mngr=
     (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
 
