Bug #10064 udf deinit not called when using PreparedStatements
Submitted: 21 Apr 2005 15:39 Modified: 9 Nov 2007 9:27
Reporter: Trevor Kramer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:3.1 OS:Linux (RedHat 4)
Assigned to: Hartmut Holzgraefe CPU Architecture:Any

[21 Apr 2005 15:39] Trevor Kramer
Description:
There was a bug introduced in the 3.1 series that is not present in the 3.0 series (at least not in 3.0.15) where when calling a udf from a PreparedStatement the deinit method is never called and a memory leak results when memory is allocated in the init call.

How to repeat:
compile this as a udf

#include <my_global.h>
#include <mysql.h>
#include <m_string.h>
                                                                                
                                                                                
          
#include <iostream>
                                                                                
                                                                                
          
namespace std {
  extern ostream cerr;
}
                                                                                
                                                                                
          
extern "C" {
    my_bool example_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
    void example_deinit(UDF_INIT *initid);
    char* example(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
*length, char *is_null, char *error);
}
                                                                                
                                                                                
          
my_bool example_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
    std::cerr << "example_init" << std::endl;
    return 0;
}
                                                                                
                                                                                
          
void example_deinit(UDF_INIT *initid) {
    std::cout << "example_deinit" << std::endl;
}
                                                                                
                                                                                
          
char* example(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
*length, char *is_null, char *error) {
    *is_null = 1;
    return NULL;
}

and install it with this command

CREATE FUNCTION example RETURNS STRING SONAME "library_name.so";

call the function from a PreparedStatement

and look in the server log for output - you will see

example_init
example_init

with no calls to deinit

Suggested fix:
Use the 3.0 series
[27 Apr 2005 17:12] Mark Matthews
Changed to a server bug, as the server handles all of the UDF calling when using server-side prepared statements. This is unrelated to JDBC or Connector/J.
[27 May 2005 19:06] Hartmut Holzgraefe
Can you please check whether this persists with MySQL 4.1.12?
I assume this is a duplicate of bug #6809 so it should be fixed by now.
[27 Jun 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[9 Nov 2007 9:27] Hartmut Holzgraefe
Reporter/Customer believes that this problem has been resolved