From f5f2a8a11223e87c28e1386bdf840af088fc7248 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jun 2007 22:07:44 +0200 Subject: [PATCH] fix for memory leak in _ma_scan_init_block_record() (Valgrind error): make Maria support multiple calls to rnd_init() without an rnd_end() call in between. storage/maria/ma_blockrec.c: as explained in sql/handler.h, multiple calls to rnd_init() without a rnd_end() in between, are possible, and engine must be prepared to that. So in _ma_scan_init_block_record(), we allocate a buffer only if we have not yet one. --- storage/maria/ma_blockrec.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index 27190f4e04c..1d7f96f6557 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -3315,12 +3315,16 @@ my_bool _ma_cmp_block_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def, my_bool _ma_scan_init_block_record(MARIA_HA *info) { - byte *ptr; DBUG_ENTER("_ma_scan_init_block_record"); - if (!(ptr= (byte *) my_malloc(info->s->block_size * 2, MYF(MY_WME)))) + /* + bitmap_buff may already be allocated if this is the second call to + rnd_init() without a rnd_end() in between, see sql/handler.h + */ + if (!(info->scan.bitmap_buff || + ((info->scan.bitmap_buff= + (byte *) my_malloc(info->s->block_size * 2, MYF(MY_WME)))))) DBUG_RETURN(1); - info->scan.bitmap_buff= ptr; - info->scan.page_buff= ptr + info->s->block_size; + info->scan.page_buff= info->scan.bitmap_buff + info->s->block_size; info->scan.bitmap_end= info->scan.bitmap_buff + info->s->bitmap.total_size; /* Set scan variables to get _ma_scan_block() to start with reading bitmap */