Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Safemalloc error in custom storage engine

From: Guilhem Bichot <guilhem(at)mysql.com>
Date: Wed Aug 01 2007 - 16:23:17 EDT


Hello,

On Wed, Aug 01, 2007 at 02:21:42PM -0500, Timothy P Clark wrote:
> Guilhem Bichot <guilhem@mysql.com> wrote on 08/01/2007 10:25:39 AM:
>
> > Hello,
> >
> > On Wed, Aug 01, 2007 at 09:42:14AM -0500, Timothy P Clark wrote:
> > > I'm working on developing a custom storage engine, and I'm encountering
> a
> > > strange error that is stumping me. I aplogize for the length of my
> posting,
> > > but I wanted to provide as much info as I could.
> > <cut>
> >
> > > Given that the source code is identical and that the traced allocations
> up
> > > to this point are identical, what could be causing this safemalloc
> error in
> > > my engine only?
> > >
> > > Has anyone else encountered this? What are the next steps I need to
> take to
> > > debug this?
> >
> > Are the compilation (compiling, linking etc) commands exactly
> > identical between "example" and your engine? You could just attach the
> > output of "cd storage/<engine>; make clean; make" for "example" and
> > for your engine, here.
>
> That's a good question. I hadn't thought about linking differences. The
> make commands are in fact different, because I was still linking to a
> module and a couple of libraries that were needed before I went back to the
> base example code. In fact, I've narrowed it down to the following line in
> my Makefile:
> ha_myengine_la_LIBADD = ... -L$(top_builddir)/mysys/ -lmysys
>
> If I remove the linkage to the mysys library, all is well. However, I
> originally added this linkage for a reason. I was using my_malloc for
> memory allocations (as suggested in the MySQL Internals Coding Guidelines),
> and my .so refused to load because it couldn't resolve to _mymalloc. Seeing
> that _mymalloc was defined in libmysys.a, I figured that the best way to
> get around that problem was to link my storage engine to that library.

ok, this is the issue.

> Was this the wrong thing to do? Are there other pluggable SEs using
> my_malloc? I'm still not sure that I understand why this is causing heap
> corruption (or whatever safemalloc is complaining about), but I suppose I
> can go back to using standard malloc for now.

safemalloc is a library we use to detect wrong memory usage (memory leaks for example).
If you use my_malloc, you have to link with libmysys, true, it's where my_malloc is. Depending on how it was built (compiler flags), libmysys' my_malloc() internally uses safemalloc or plain malloc(). But the problem is that your engine and libmysys must have the same characteristics: they must either both use safemalloc or both not, or there is an "impedance mismatch", maybe what you are seeing.
Can you please paste here the "configure" command-line which was used in the build of the mysql server source tree which includes libmysys? If you don't remember it, search for CONF_COMMAND in config.log. With that, we should be able to find proper compiler flags for your engine.
I know that PBXT faces similar issues:
http://pbxt.blogspot.com/
"Both MYSQL and PBXT must be compiled with the same value for the --with-debug switch (on/off/full). If not, the plug-in will not load."

And if too complicated, falling back to plain malloc() is not that bad.

-- 
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Guilhem Bichot 
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Lead Software Engineer
/_/  /_/\_, /___/\___\_\___/   Bordeaux, France
       <___/   www.mysql.com   

-- 
MySQL Internals Mailing List
For list archives: 
http://lists.mysql.com/internals
To unsubscribe:    
http://lists.mysql.com/internals?unsub=lists@pantek.com
Received on Wed Aug 1 16:17:06 2007

This archive was generated by hypermail 2.1.8 : Thu Aug 09 2007 - 19:06:23 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library