Bug #293 Memory leaks?
Submitted: 15 Apr 2003 10:56 Modified: 12 Jun 2003 5:47
Reporter: chris loelke Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.12-debug-log OS:Other (SCO Openserver 5.0.6)
Assigned to: CPU Architecture:Any

[15 Apr 2003 10:56] chris loelke
Description:

My system as per mysqlbug
C compiler:    2.95.3           
C++ compiler:  2.95.3                 
System: SCO 3.2 5.0.6 i386 
Compilation info: CC='gcc'                                                    
CFLAGS='-O3 -mcpu=pentiumpro -felide-constructors -fno-exceptions -fno-rtti ' 
CXX='gcc'  CXXFLAGS='-O3 -mcpu=pentiumpro -felide-constructors -fno-exceptions
-fno-rtti'  LDFLAGS=''  ASFLAGS=''                                            
Configure command:                                                    
./configure '--prefix=/usr/local/mysql' '--enable-thread-safe-client' 
 '--enable-local-infile' '--with-named-z-libs=no' '--disable-shared'  
 '--without-docs' '--without-innodb' '--with-debug=full'

the errors and warnings produced (a partial list from warnings file):
Warning: Not freed memory segments: 75                           
Warning: Memory that was not free'ed (1280078 bytes):            
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 557, 'table.cc'

a partial list from master.err
CURRENT_TEST: alias                                              
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 557, 'table.cc'     
Error: Freeing wrong aligned pointer at line 557, 'table.cc'     
Error: Reallocating wrong aligned pointer at line 277, 'array.c' 
Error: Freeing wrong aligned pointer at line 63, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 98, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 105, 'mi_close.c'   
Error: Freeing wrong aligned pointer at line 665, 'table.cc'     
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 324, 'sql_base.cc'  
Error: Freeing wrong aligned pointer at line 63, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 98, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 105, 'mi_close.c'   
Error: Freeing wrong aligned pointer at line 665, 'table.cc'     
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 175, 'my_alloc.c'   
     
Error: Freeing wrong aligned pointer at line 557, 'table.cc'     
Error: Reallocating wrong aligned pointer at line 277, 'array.c' 
Error: Freeing wrong aligned pointer at line 63, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 98, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 105, 'mi_close.c'   
Error: Freeing wrong aligned pointer at line 665, 'table.cc'     
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 324, 'sql_base.cc'  
Error: Freeing wrong aligned pointer at line 63, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 91, 'my_open.c'     
Error: Freeing wrong aligned pointer at line 98, 'mi_close.c'    
Error: Freeing wrong aligned pointer at line 105, 'mi_close.c'   
Error: Freeing wrong aligned pointer at line 665, 'table.cc'     
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
Error: Freeing wrong aligned pointer at line 169, 'my_alloc.c'   
----
additional partial list form master.err
Error: Freeing wrong aligned pointer at line 936, 'mysqld.cc'                 
                                                                              
User time 0.07, System time 0.17                                              
Maximum resident set size 0, Integral resident set size 134509948             
Non-physical pagefaults -2147066535, Physical pagefaults 0, Swaps 134509964   
Blocks in 134783992 out 0, Messages in 0 out 134509964, Signals 134783979     
Voluntary context switches 0, Involuntary context switches 135957180          
Warning: Not freed memory segments: 75                                        
Warning: Memory that was not free'ed (1280078 bytes):                         
             4 bytes at 0x00838119c, allocated at line  629 in 'filesort.cc'  
         65536 bytes at 0x0083f00bc, allocated at line  178 in 'mf_iocache.c' 
          5400 bytes at 0x0083eeb84, allocated at line   50 in 'hp_block.c'   
           500 bytes at 0x0083da0dc, allocated at line   60 in 'hp_open.c'    
          1012 bytes at 0x0083d49dc, allocated at line   74 in 'mi_dynrec.c'  
          1026 bytes at 0x0083d2554, allocated at line  603 in 'mi_open.c'    
          5256 bytes at 0x0083d3534, allocated at line   49 in 'mulalloc.c'   
          1936 bytes at 0x0083d2d84, allocated at line   94 in 'my_alloc.c'   
           968 bytes at 0x0083d299c, allocated at line   94 in 'my_alloc.c'   
          1179 bytes at 0x0083d097c, allocated at line  745 in 'table.cc'     
          1856 bytes at 0x0083d021c, allocated at line   94 in 'my_alloc.c'   
          1096 bytes at 0x0083cfdb4, allocated at line   94 in 'my_alloc.c'   
             1 bytes at 0x00837ae5c, allocated at line   80 in 'table.cc'     
           968 bytes at 0x0083cf9cc, allocated at line   94 in 'my_alloc.c'   

              

How to repeat:
brand new system, do a make install then run the mysql-test-run

Suggested fix:
I am assuming, probably incorrectly that the errors are all related to
a mis-declaration in a header file.

I would be willing to help isolate this, even try some other
versions of GCC.
[16 Apr 2003 10:42] Indrek Siitan
Do you have an SQL script with a repeatable test case that, ran against 
the database server, generates those errors?
[16 Apr 2003 10:49] chris loelke
in order to reproduce this all one has to do is run
the perl script typically in usr/local/mysql/mysql-test
name of the script is mysql-test-run.  This is the standard
script that comes with mysql distributions.  It fails
on the very first test (Alias).
[16 Apr 2003 10:51] MySQL Verification Team
We test thoroughly all our builds with all tests we have.

Therefore this is an error in building MySQL.

Use our binary instead.
[16 Apr 2003 10:54] chris loelke
you dont have a binary for this platform available,
the one that is sometimes available has memory leaks too.
[16 Apr 2003 11:00] MySQL Verification Team
If our binary issues memory errors that it is due to 
differences in patch levels between our OS and yours.
[16 May 2003 2:15] Michael Widenius
I must first appoligize for the way we have handled this bug report in the past. It was unprofessionally done and I have talked with the developer that handled this case to ensure that this will not happen again.

Back to your problem:

MySQL is known to work on OpenServer 5.0.6 with your gcc version, so we need some more information to know what is wrong.

I we could get a trace file from just one test that fails, then we should be able to figure out what is wrong.

Try to do this:

cd mysql-test
./mysql-test-run --local --debug alias
if this fails with  'Freeing wrong aligned pointer' then please do the following:
- Create a README file with contains a copy of the text in this ticket
- Create a tar file that contains the README file and the file
  var/tests/master.trace
- Upload this to ftp://support.mysql.com/pub/mysql/secret
- Add a new comment to this bug that contains the name of the file

If we can't solve it from the above, the other option is if you can give us access to a system where this happens so that we can login to it and debug this ourselves.
[21 May 2003 8:09] chris loelke
file sco506bug.tar uploaded.
the test fails with  'Freeing wrong aligned pointer' and
it also never completes.
[22 May 2003 8:47] MySQL Verification Team
Sorry for the previous comments.

Can you please send us more info. We need to track a problem.

One way is to run the following command which should give us the
information we need:

./mysql-test-run --debug alias

and then, please,upload the var/log/master.trace file.

If you have any further questions, you can use this record to post them.

Thanks in advance.
[22 May 2003 8:51] MySQL Verification Team
I see that you have uploaded a file.

We shall soon take a look at it and we shall advise you of our findings.
[27 May 2003 8:23] MySQL Verification Team
Seems like the error is just in the pointer alignment.

Can you please try changing line 639 in my_global.h into:

#define ALIGN_SIZE(A)	MY_ALIGN((A),4)

and see if you still get the debug warnings
[27 May 2003 9:27] chris loelke
Yes, that fixed the problem with the pointer alignment, very good call :)
FYI, the sizeof(double) is 8 on SCO...

Next issue.. (hopefully the last), when running all the tests I still get
a failure as per below.

constraints               0.000000 0.010000 0.198983       [ pass ]            
count_distinct            0.010000 0.050000 0.479109       [ pass ]            
count_distinct2           0.770000 1.820000 1.105322       [ pass ]            
create                    0.020000 0.020000 1.122247       [ pass ]            
ERROR: /usr/mysql/mysql-4.0.12/mysql-test/var/run/master.pid was not created in
30 seconds;  Aborting                                                          
#
[27 May 2003 10:08] MySQL Verification Team
This is completely different issue.

Check messages in master error log.

See whether it happens always in the same test.and whether it is in create or
ctype-collate.
Then try running that test alone, like:

cd mysql-test
./mysql-test-run --local ctype-collate
[2 Jun 2003 11:03] MySQL Verification Team
This problem was diagnosed.

We need to have ALIGN_SIZE as a config variable and have to write a test for
configure to determine it's value, as some OS's, like SCO align pointers at 4 and not at the sizeof(double) alignment.
[12 Jun 2003 5:47] Michael Widenius
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html

This will be fixed in 4.0.14

The bug was that one structure that was used by safemalloc was not 8 byte aligned with the compiler you used.