This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: A bug in g++ compiler


> Both temporary and res share mysql_res. And it is a pointer to
> MYSQL_RES struct, pretty complicated stuff, which holds arrays, linked 
> lists etc, which is freed in a destructor.
> 
> So, yes you are right, but ALL fields of a temp are destroyed. But
> several of those fields are pointers to very complex structures
> pointers, dynamically alloced and created. As the address is the same
> for both res and temp, when temp is destroyed, so are the most
> valuable fields in the res !!!!!
> 
> Do you get my thoughts ??? What should I do ??

As a first step, you should try to fully understand the problem. Then
you should try to analyse where the problem lies. Is it

a) a compiler bug, or
b) a bug in the Mysql classes, or
c) a bug in your application?

If you think there is a compiler bug, please feel free to re-report
it; please pick a better Subject: than "A bug in g++ compiler" next
time.

If you think this is a Mysql bug, you might want to contact the
respective authors for help. You did send full source, so I don't see
everything what's going on. I don't want to perform the complete
analysis, either.

From the snippets I have, it seems
- the destructor deletes storage associated with a MysqlResUse object
  ("ALL fields of a temp are destroyed")
- apparently, the assignment operator does not properly duplicate all
  necessary fields. This is surprising, though, since it does have a
  copy operation.

This is a typical C++ problems, and there is a variety of solutions to
it:
- the ownership to embedded storage, and the pointers to it, could move
  in an assignment. So the right-hand side object would get null ppinters.

- you could have explicit copy operations on assignment and copy
  construction, duplicating the embedded storage. This appears to be
  the approach of Mysql. There might be a bug, or you might be missing
  some important information.

- reference counting could be used, to only delete the storage when
  the reference count goes to zero.

I feel this is not a g++ problem anymore; please take this to a Mysql
group, or to a general C++ discussion group.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]