List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:February 11 2009 8:12am
Subject:bzr commit into mysql-6.0-backup branch (jorgen.loland:2764) Bug#41250
View as plain text  
#At file:///localhome/jl208045/mysql/mysql-6.0-backup-41250/

 2764 Jorgen Loland	2009-02-11
      Bug#41250 - Resources not freed properly in the backup stream library
            
      There are a lot of occurences where resources are not freed when entering error handling code. This patch frees up these resources.
modified:
  sql/backup/kernel.cc
  sql/backup/stream_v1.c

per-file messages:
  sql/backup/kernel.cc
    Delete iterators if error is encountered.
  sql/backup/stream_v1.c
    Delete iterators if errors are encountered.
=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2009-02-09 18:17:55 +0000
+++ b/sql/backup/kernel.cc	2009-02-11 08:12:45 +0000
@@ -1191,6 +1191,8 @@ int Backup_restore_ctx::restore_triggers
         DBUG_ASSERT(obj->m_obj_ptr);
         if (events.push_back(obj))
         {
+          delete it;
+          delete dbit;
           // Error has been reported, but not logged to backup logs
           DBUG_RETURN(fatal_error(log_error(ER_OUT_OF_RESOURCES))); 
         }

=== modified file 'sql/backup/stream_v1.c'
--- a/sql/backup/stream_v1.c	2008-12-18 21:46:36 +0000
+++ b/sql/backup/stream_v1.c	2009-02-11 08:12:45 +0000
@@ -641,7 +641,7 @@ int bstream_rd_db_catalogue(backup_strea
 */
 int bstream_wr_catalogue(backup_stream *s, struct st_bstream_image_header *cat)
 {
-  void *it;
+  void *it= NULL;
   blob *name;
   struct st_bstream_db_info *db_info;
   struct st_bstream_ts_info *ts_info;
@@ -662,6 +662,7 @@ int bstream_wr_catalogue(backup_stream *
   CHECK_WR_RES(bstream_wr_byte(s,0x00));
 
   bcat_iterator_free(cat,it);
+  it= NULL;
 
   /* list of users */
 
@@ -678,6 +679,7 @@ int bstream_wr_catalogue(backup_stream *
   CHECK_WR_RES(bstream_wr_byte(s,0x00));
 
   bcat_iterator_free(cat,it);
+  it= NULL;
 
   /* list of table spaces */
 
@@ -694,6 +696,7 @@ int bstream_wr_catalogue(backup_stream *
   CHECK_WR_RES(bstream_wr_byte(s,0x00));
 
   bcat_iterator_free(cat,it);
+  it= NULL;
 
   /* list of databases */
 
@@ -709,6 +712,7 @@ int bstream_wr_catalogue(backup_stream *
   }
 
   bcat_iterator_free(cat,it);
+  it= NULL;
 
   /* db catalogues */
 
@@ -724,9 +728,14 @@ int bstream_wr_catalogue(backup_stream *
   }
 
   bcat_iterator_free(cat,it);
+  it= NULL;
 
   wr_error:
 
+  // Free iterator if not already done
+  if (it)
+    bcat_iterator_free(cat,it);
+
   return ret;
 }
 
@@ -748,7 +757,7 @@ int bstream_rd_catalogue(backup_stream *
   int ret= BSTREAM_OK;
   unsigned short int flags;
   unsigned int len;
-  void *iter;
+  void *iter= NULL;
   struct st_bstream_item_info item;
   struct st_bstream_db_info *db_info;
 
@@ -862,19 +871,27 @@ int bstream_rd_catalogue(backup_stream *
   while ((db_info= (struct st_bstream_db_info*) bcat_iterator_next(cat,iter)))
   {
     if (ret != BSTREAM_EOC)
+    {
+      bcat_iterator_free(cat,iter);
       return BSTREAM_ERROR;
-
+    }
+    
     CHECK_RD_OK(bstream_next_chunk(s));
     CHECK_RD_RES(bstream_rd_db_catalogue(s,cat,db_info));
   }
 
   bcat_iterator_free(cat,iter);
+  iter= NULL;
 
   if (bcat_close(cat) != BSTREAM_OK)
     return BSTREAM_ERROR;
 
   rd_error:
 
+  // Free iterator if not already done
+  if (iter)
+    bcat_iterator_free(cat,iter);
+
   return ret;
 }
 
@@ -1010,7 +1027,7 @@ int bstream_rd_item_type(backup_stream *
 int bstream_wr_db_catalogue(backup_stream *s, struct st_bstream_image_header *cat,
                             struct st_bstream_db_info *db_info)
 {
-  void *iter;
+  void *iter= NULL;
   struct st_bstream_dbitem_info *item;
   int ret= BSTREAM_OK;
   bool catalogue_empty= TRUE;
@@ -1036,12 +1053,17 @@ int bstream_wr_db_catalogue(backup_strea
   }
 
   bcat_db_iterator_free(cat, db_info, iter);
+  iter= NULL;
 
   if (catalogue_empty)
     CHECK_WR_RES(bstream_wr_item_type(s,BSTREAM_IT_LAST));
 
   wr_error:
 
+  // Free iterator if not already done
+  if (iter)
+    bcat_iterator_free(cat,iter);
+
   return ret;
 }
 
@@ -1198,7 +1220,7 @@ int read_and_create_items(backup_stream 
 /** Write meta-data section of a backup image */
 int bstream_wr_meta_data(backup_stream *s, struct st_bstream_image_header *cat)
 {
-  void *iter, *titer;
+  void *iter= NULL, *titer= NULL;
   struct st_bstream_item_info *item;
   struct st_bstream_db_info   *db_info;
   int ret= BSTREAM_OK;
@@ -1223,6 +1245,7 @@ int bstream_wr_meta_data(backup_stream *
     CHECK_WR_RES(bstream_wr_item_type(s,BSTREAM_IT_LAST));
 
   bcat_iterator_free(cat,iter);
+  iter= NULL;
 
   /* tables */
 
@@ -1239,7 +1262,10 @@ int bstream_wr_meta_data(backup_stream *
     titer= bcat_db_iterator_get(cat,db_info);
 
     if (!titer)
+    {
+      bcat_iterator_free(cat,iter);
       return BSTREAM_ERROR;
+    }
 
     item_written= FALSE;
     while ((item= (struct st_bstream_item_info*)
@@ -1257,9 +1283,11 @@ int bstream_wr_meta_data(backup_stream *
       CHECK_WR_RES(bstream_wr_item_type(s,BSTREAM_IT_LAST));
 
     bcat_db_iterator_free(cat,db_info,titer);
+    titer= NULL;
   }
 
   bcat_iterator_free(cat,iter);
+  iter= NULL;
 
   /* if we found no databases in the catalogue, we are done */
   if (!has_db)
@@ -1283,6 +1311,7 @@ int bstream_wr_meta_data(backup_stream *
   }
 
   bcat_iterator_free(cat,iter);
+  iter= NULL;
 
   /* per-table items */
 
@@ -1302,7 +1331,13 @@ int bstream_wr_meta_data(backup_stream *
   }
 
 wr_error:
-  bcat_iterator_free(cat,iter);
+
+  // Free iterators if not already done
+  if (titer)
+    bcat_iterator_free(cat,titer);
+
+  if (iter) 
+    bcat_iterator_free(cat,iter);
 
   return ret;
 }
@@ -1319,7 +1354,7 @@ wr_error:
 */
 int bstream_rd_meta_data(backup_stream *s, struct st_bstream_image_header *cat)
 {
-  void *iter;
+  void *iter= NULL;
   struct st_bstream_db_info *db_info;
   int ret=BSTREAM_OK;
   bool has_db= FALSE;
@@ -1340,13 +1375,17 @@ int bstream_rd_meta_data(backup_stream *
     has_db= TRUE;
 
     if (ret != BSTREAM_EOC)
+    {
+      bcat_iterator_free(cat,iter);
       return BSTREAM_ERROR;
-
+    }
+    
     CHECK_RD_OK(bstream_next_chunk(s));
     CHECK_RD_RES(read_and_create_items(s,cat,TABLE_ITEM));
   }
 
   bcat_iterator_free(cat,iter);
+  iter= NULL;
 
   /* if image has no databases, there is nothing more to read */
 
@@ -1375,6 +1414,10 @@ int bstream_rd_meta_data(backup_stream *
 
   rd_error:
 
+  // Free iterator if not already done
+  if (iter) 
+    bcat_iterator_free(cat,iter);
+
   return ret;
 }
 

Thread
bzr commit into mysql-6.0-backup branch (jorgen.loland:2764) Bug#41250Jorgen Loland11 Feb