Bug #43090 ARCHIVE engine related warnings on Windows debug build

Submitted: 22 Feb 2009 16:05 Modified: 15 Apr 2009 1:40
Reporter: Ingo Strüwing Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Archive storage engine Severity:S3 (Non-critical)
Version:6.0 OS:Windows
Assigned to: Ingo Strüwing CPU Architecture:Any

[22 Feb 2009 16:05] Ingo Strüwing
Description:
main.partition_archive                   [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 09:45:31
file_name	line
C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing pointer out of range at line 399, '.\ha_archive.cc'
C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing pointer out of range at line 399, '.\ha_archive.cc'
C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing pointer out of range at line 399, '.\ha_archive.cc'
... (many of these follow)
^ Found warnings!!
ok

main.archive                             [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 09:59:42
file_name	line

C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/2/mysqld.1/mysqld.err	Error: Freeing pointer out of range at line 399, '.\ha_archive.cc'
... (many of these follow)

main.archive_aio_posix                   [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 09:59:44
file_name	line

C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing unallocated data at line 399, '.\ha_archive.cc'
... (many of these follow)

main.archive_bitfield                    [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 10:00:10
file_name	line

C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/2/mysqld.1/mysqld.err	Error: Freeing unallocated data at line 399, '.\ha_archive.cc'
... (many of these follow)

main.archive_gis                         [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 10:00:12
file_name	line

C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing unallocated data at line 399, '.\ha_archive.cc'
... (many of these follow)

main.mysqldump-max                       [ fail ]  Found warnings/errors in server log file!
        Test ended at 2009-02-18 10:43:23
file_name	line

C:/cygwin/home/istruewing/bzrroot/mysql-6.0-bug38133-6/mysql-test/var/1/mysqld.1/mysqld.err	Error: Freeing unallocated data at line 399, '.\ha_archive.cc'
^ Found warnings!!
ok

The offending line in ha_archive.cc is:
    my_free((uchar*) share, MYF(0));
That's in free_share().
The share is allocated in get_share() at this line:
    if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
                          &share, sizeof(*share),
                          &tmp_name, length+1,
                          NullS)) 

When running with --debug, the trace shows that the saher is allocated with my_malloc(), while it is freed with _myfree(), which is part of SAFEMALLOC. No wonder that it complains. It didn't record the allocation.

In the top-level CMakeLists.txt, we have this:

# Do not use SAFEMALLOC for Windows builds, as Debug CRT has the same functionality
# Neither SAFE_MUTEX works on Windows and it has been explicitely undefined in 
# my_pthread.h
IF(NOT WIN32)
  SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
  SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
ENDIF(NOT WIN32)

In storage/archive/CMakeLists.txt, we explicitly define SAFEMALLOC and SAFE_MUTEX. This is not a big problem, as long as all memory allocated by ARCHIVE is also freed by it and vice versa. my_malloc() and my_free() are macros that evaluate to _mymalloc() and _myfree() if SAFEMALLOC is defined. Other engines do also explicitly turn these on, whithout problems.

However, ha_archive.cc uses my_multi_malloc(), which is not redefined by SAFEMALLOC. It calls my_malloc() internally to do the final allocation. But since mysys is not compiled with SAFEMALLOC, it calls the real my_malloc().

How to repeat:
Make a debug build on Windows.
Run the mentioned tests.

Suggested fix:
=== modified file 'storage/archive/CMakeLists.txt'
--- storage/archive/CMakeLists.txt      2008-01-30 02:58:57 +0000
+++ storage/archive/CMakeLists.txt      2009-02-22 16:01:25 +0000
@@ -13,8 +13,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+#
+# NOTE: The use of my_multi_malloc() in ha_archive.cc excludes the
+# definition of SAFEMALLOC and SAFE_MUTEX here, as long as it is not
+# defined in the top-level CMakeList.txt. So do not define it here
+# explicitly, but inherit from the top-level file.
+#
+#SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+#SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
                     ${CMAKE_SOURCE_DIR}/sql
[22 Feb 2009 16:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/67113

2765 Ingo Struewing	2009-02-22
      Bug#43090 - ARCHIVE engine related warnings on Windows debug build
      
      A windows debug build created warnings in the error log.
      In a windows debug build, we do not define SAFEMALLOC and SAFE_MUTEX.
      But the ARCHIVE engine explicitly defined them in CMakeLists.txt.
      Ha_archive.cc uses my_multi_malloc(). This is part of mysys, which,
      like most parts of the server, are compiled without SAFEMALLOC.
      So my_multi_malloc() calls my_malloc() directly and is not
      redirected to the SAFEMALLOC function _mymalloc(). But since
      ha_archive.cc frees the allocated memory with my_free(), which
      is redefined to _myfree(), SAFEMALLOC complains about a free, for
      which it didn't see an allocation.
      
      Fixed by not explicitly defining SAFEMALLOC and SAFE_MUTEX in
      ARCHIVE's CMakeLists.txt.
     @ storage/archive/CMakeLists.txt
        Bug#43090 - ARCHIVE engine related warnings on Windows debug build
        Disabled explicit definition of SAFEMALLOC and SAFE_MUTEX.
[25 Feb 2009 13:10] Ingo Strüwing
Queued to mysql-6.0-backup.
[26 Mar 2009 12:34] Bugs System
Pushed into 6.0.11-alpha (revid:alik@sun.com-20090326121822-pt84kzxxayzho4mn) (version source revid:rafal.somla@sun.com-20090302164601-znhm4tadplfi2iqu) (merge vers: 6.0.11-alpha) (pib:6)
[15 Apr 2009 1:40] Paul DuBois
Cosmetic change to silence warnings. No changelog entry needed.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.057 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.