costin 01/12/12 15:36:01 Modified: jk/native2/common jk_ajp14_worker.c jk_channel_socket.c jk_env.c jk_handler_response.c jk_jni_worker.c jk_msg_ajp.c jk_uriMap.c jk_workerEnv.c jk/native2/server/apache2 jk_logger_apache2.c Log: Hunting malloc/frees. minor fixes. Cosmetic: change p to pool for easier grepping. We now have only 2 places where malloc/free is used ( only at startup time). We still need to check and make sure the pools are destroyed/reset when needed, but the hard part was getting all the code to use pools. ( note that I haven't tested the jk_pool code for a while, I'm using the apr_pool. When I start udating the other connectors I'll have to use jk_pool anyway ) Revision Changes Path 1.7 +4 -6 jakarta-tomcat-connectors/jk/native2/common/jk_ajp14_worker.c Index: jk_ajp14_worker.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_ajp14_worker.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- jk_ajp14_worker.c 2001/12/12 21:45:55 1.6 +++ jk_ajp14_worker.c 2001/12/12 23:36:01 1.7 @@ -131,14 +131,13 @@ w->connect_retry_attempts= AJP_DEF_RETRY_ATTEMPTS; w->channel= NULL; + w->secret= NULL; w->validate= jk_worker_ajp14_validate; w->init= jk_worker_ajp14_init; w->get_endpoint= jk_worker_ajp14_getEndpoint; w->destroy=jk_worker_ajp14_destroy; - w->logon= NULL; - *result = w; l->jkLog(l, JK_LOG_INFO, "ajp14.factory() Created %s %s\n", @@ -172,7 +171,6 @@ "ajp14.validate() No secretkey, use AJP13\n"); proto=AJP13_PROTO; aw->proto= AJP13_PROTO; - aw->logon= NULL; } if (proto == AJP13_PROTO) { @@ -243,7 +241,7 @@ } /* Check if we must execute a logon after the physical connect */ - if (ae->worker->logon == NULL) + if (ae->worker->secret == NULL) return JK_TRUE; /* Do the logon process */ @@ -519,10 +517,10 @@ if( secret_key==NULL ) { proto=AJP13_PROTO; _this->proto= AJP13_PROTO; - _this->logon= NULL; + _this->secret=NULL; } else { /* Set Secret Key (used at logon time) */ - _this->secret = strdup(secret_key); + _this->secret = _this->pool->pstrdup(_this->pool, secret_key); } 1.7 +13 -5 jakarta-tomcat-connectors/jk/native2/common/jk_channel_socket.c Index: jk_channel_socket.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_channel_socket.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- jk_channel_socket.c 2001/12/12 21:53:58 1.6 +++ jk_channel_socket.c 2001/12/12 23:36:01 1.7 @@ -64,6 +64,8 @@ * - port * - ndelay * + * This channel should 'live' as much as the workerenv. It is stateless. + * It allocates memory for endpoint private data ( using endpoint's pool ). * * @author: Gal Shachor <[EMAIL PROTECTED]> * @author: Costin Manolache @@ -288,7 +290,8 @@ jk_channel_socket_data_t *sd=endpoint->channelData; if( sd==NULL ) { sd=(jk_channel_socket_data_t *) - malloc( sizeof( jk_channel_socket_data_t )); + endpoint->pool->calloc( endpoint->pool, + sizeof( jk_channel_socket_data_t )); endpoint->channelData=sd; } sd->sock=sock; @@ -306,8 +309,12 @@ jk_channel_socket_data_t *chD=endpoint->channelData; if( chD==NULL ) return JK_FALSE; - sd=chD->sock; + sd=chD->sock; + chD->sock=-1; + /* nothing else to clean, the socket_data was allocated ouf of + * endpoint's pool + */ return jk_close_socket(sd); } @@ -399,7 +406,8 @@ -int JK_METHOD jk_channel_socket_factory(jk_env_t *env, jk_pool_t *pool, void **result, +int JK_METHOD jk_channel_socket_factory(jk_env_t *env, jk_pool_t *pool, + void **result, const char *type, const char *name) { jk_channel_t *_this; @@ -409,10 +417,10 @@ *result=NULL; return JK_FALSE; } - _this=(jk_channel_t *)pool->alloc(pool, sizeof( jk_channel_t)); + _this=(jk_channel_t *)pool->calloc(pool, sizeof( jk_channel_t)); _this->_privatePtr= (jk_channel_socket_private_t *) - pool->alloc( pool, sizeof( jk_channel_socket_private_t)); + pool->calloc( pool, sizeof( jk_channel_socket_private_t)); _this->recv= &jk_channel_socket_recv; _this->send= &jk_channel_socket_send; 1.5 +5 -1 jakarta-tomcat-connectors/jk/native2/common/jk_env.c Index: jk_env.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_env.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- jk_env.c 2001/12/06 22:54:44 1.4 +++ jk_env.c 2001/12/12 23:36:01 1.5 @@ -85,8 +85,11 @@ const char *name ) { jk_env_objectFactory_t result; + /* malloc/free: this is really temporary, and is executed only at setup + time, not during request execution. We could create a subpool or alloc + from stack */ char *typeName= - (char *)calloc( (strlen(name) + strlen(type) + 2 ), sizeof( char )); + (char *)malloc( (strlen(name) + strlen(type) + 2 ) * sizeof( char )); strcpy(typeName, type ); strcat( typeName, "/" ); @@ -99,6 +102,7 @@ /** XXX add check for the type */ result=(jk_env_objectFactory_t)map_get( env->_registry, typeName, NULL ); + free( typeName ); return result; } 1.6 +3 -3 jakarta-tomcat-connectors/jk/native2/common/jk_handler_response.c Index: jk_handler_response.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_handler_response.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- jk_handler_response.c 2001/12/12 21:34:47 1.5 +++ jk_handler_response.c 2001/12/12 23:36:01 1.6 @@ -116,7 +116,7 @@ { int err; unsigned i; - jk_pool_t * p = s->pool; + jk_pool_t * pool = s->pool; s->status = msg->getInt(msg); s->msg = (char *)msg->getString(msg); @@ -128,8 +128,8 @@ s->out_header_values = NULL; if (s->out_headers > 0 ) { - s->out_header_names = p->alloc(p, sizeof(char *) * s->out_headers); - s->out_header_values = p->alloc(p, sizeof(char *) * s->out_headers); + s->out_header_names = pool->alloc(pool, sizeof(char *) * s->out_headers); + s->out_header_values = pool->alloc(pool, sizeof(char *) * s->out_headers); if (s->out_header_names==NULL || s->out_header_values==NULL) { 1.8 +83 -75 jakarta-tomcat-connectors/jk/native2/common/jk_jni_worker.c Index: jk_jni_worker.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_jni_worker.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- jk_jni_worker.c 2001/12/06 22:54:44 1.7 +++ jk_jni_worker.c 2001/12/12 23:36:01 1.8 @@ -59,7 +59,7 @@ * Description: In process JNI worker * * Author: Gal Shachor <[EMAIL PROTECTED]> * * Based on: * - * Version: $Revision: 1.7 $ * + * Version: $Revision: 1.8 $ * ***************************************************************************/ #if !defined(WIN32) && !defined(NETWARE) @@ -264,13 +264,13 @@ } #endif -static char **jk_parse_sysprops(jk_pool_t *p, - const char *sysprops) +static char **jk_parse_sysprops(jk_pool_t *pool, + const char *sysprops) { char **rc = NULL; - if(p && sysprops) { - char *prps = p->pstrdup(p, sysprops); + if(pool && sysprops) { + char *prps = pool->pstrdup(pool, sysprops); if(prps && strlen(prps)) { unsigned num_of_prps; @@ -280,7 +280,7 @@ } } - rc = p->alloc(p, (num_of_prps + 1) * sizeof(char *)); + rc = pool->alloc(pool, (num_of_prps + 1) * sizeof(char *)); if(rc) { unsigned i = 0; char *tmp = strtok(prps, "*"); @@ -310,16 +310,16 @@ } -static void jk_append_libpath(jk_pool_t *p, +static void jk_append_libpath(jk_pool_t *pool, const char *libpath) { char *env = NULL; char *current = getenv(PATH_ENV_VARIABLE); if(current) { - env = p->alloc(p, strlen(PATH_ENV_VARIABLE) + - strlen(current) + - strlen(libpath) + 5); + env = pool->alloc(pool, strlen(PATH_ENV_VARIABLE) + + strlen(current) + + strlen(libpath) + 5); if(env) { sprintf(env, "%s=%s%c%s", PATH_ENV_VARIABLE, @@ -328,8 +328,8 @@ current); } } else { - env = p->alloc(p, strlen(PATH_ENV_VARIABLE) + - strlen(libpath) + 5); + env = pool->alloc(pool, strlen(PATH_ENV_VARIABLE) + + strlen(libpath) + 5); if(env) { sprintf(env, "%s=%s", PATH_ENV_VARIABLE, libpath); } @@ -406,20 +406,20 @@ { jni_endpoint_t *p; - l->jkLog(l, JK_LOG_DEBUG, "Into done\n"); if(!e || !*e || !(*e)->endpoint_private) { - l->jkLog(l, JK_LOG_EMERG, - "In done, assert failed - invalid parameters\n"); - return JK_FALSE; + l->jkLog(l, JK_LOG_EMERG, "jni.done() NullPointerException\n"); + return JK_FALSE; } + l->jkLog(l, JK_LOG_DEBUG, "jni.done()\n"); + p = (*e)->endpoint_private; if(p->attached) { detach_from_jvm(p->worker,l); } - free(p); + (*e)->pool->close( (*e)->pool ); *e = NULL; l->jkLog(l, JK_LOG_DEBUG, "Done ok\n"); @@ -635,32 +635,41 @@ jk_logger_t *l) { /* [V] This slow, needs replacement */ - jni_endpoint_t *p = (jni_endpoint_t *)malloc(sizeof(jni_endpoint_t)); + jk_pool_t *endpointPool; + jni_endpoint_t *e; + + endpointPool=pThis->pool->create( pThis->pool, HUGE_POOL_SIZE ); + + e = (jni_endpoint_t *)endpointPool->calloc(endpointPool, + sizeof(jni_endpoint_t)); l->jkLog(l, JK_LOG_DEBUG, "Into get_endpoint\n"); if(!pThis || ! pThis->worker_private || !pend) { l->jkLog(l, JK_LOG_EMERG, - "In get_endpoint, assert failed - invalid parameters\n"); + "jniWorker.getEndpoint() NullPointerException\n"); return JK_FALSE; } - if(p) { - p->attached = JK_FALSE; - p->env = NULL; - p->worker = pThis->worker_private; - p->endpoint.endpoint_private = p; - p->endpoint.service = service; - p->endpoint.done = done; - p->endpoint.channelData = NULL; - *pend = &p->endpoint; - - return JK_TRUE; - } else { - l->jkLog(l, JK_LOG_ERROR, "In get_endpoint, could not allocate endpoint\n"); - return JK_FALSE; + if(e==NULL) { + l->jkLog(l, JK_LOG_ERROR, + "jniWorker.getEndpoint() OutOfMemoryException\n"); + return JK_FALSE; } + + /** XXX Fix the spaghetti */ + e->attached = JK_FALSE; + e->env = NULL; + e->worker = pThis->worker_private; + e->endpoint.endpoint_private = e; + e->endpoint.service = service; + e->endpoint.done = done; + e->endpoint.channelData = NULL; + e->endpoint.pool=endpointPool; + *pend = &e->endpoint; + + return JK_TRUE; } static int JK_METHOD destroy(jk_worker_t **pThis, @@ -673,7 +682,8 @@ "Into destroy\n"); if(!pThis || !*pThis || ! (*pThis)->worker_private) { - l->jkLog(l, JK_LOG_EMERG, "In destroy, assert failed - invalid parameters\n"); + l->jkLog(l, JK_LOG_EMERG, + "In destroy, assert failed - invalid parameters\n"); return JK_FALSE; } @@ -699,7 +709,6 @@ } p->pool->close(p->pool); - free(p); l->jkLog(l, JK_LOG_DEBUG, "Done destroy\n"); @@ -710,7 +719,7 @@ char *type, char *name) { jk_logger_t *l=env->logger; - jni_worker_t *private_data; + jni_worker_t *_this; l->jkLog(l, JK_LOG_DEBUG, "Into jni_worker_factory\n"); @@ -727,57 +736,56 @@ return JK_TRUE; } - private_data = (jni_worker_t *)pool->calloc(pool, sizeof(jni_worker_t )); + _this = (jni_worker_t *)pool->calloc(pool, sizeof(jni_worker_t )); - if(!private_data) { + if(!_this) { l->jkLog(l, JK_LOG_ERROR, "In jni_worker_factory, memory allocation error\n"); return JK_FALSE; } - private_data->pool=pool; + _this->pool=pool; - private_data->name = private_data->pool->pstrdup(private_data->pool, name); + _this->name = _this->pool->pstrdup(_this->pool, name); - if(!private_data->name) { + if(!_this->name) { l->jkLog(l, JK_LOG_ERROR, "In jni_worker_factory, memory allocation error\n"); - private_data->pool->close(private_data->pool); - free(private_data); + _this->pool->close(_this->pool); return JK_FALSE; } - private_data->was_verified = JK_FALSE; - private_data->was_initialized = JK_FALSE; - private_data->jvm = NULL; - private_data->tmp_env = NULL; - private_data->jk_java_bridge_object = NULL; - private_data->jk_java_bridge_class = NULL; - private_data->jk_startup_method = NULL; - private_data->jk_service_method = NULL; - private_data->jk_shutdown_method = NULL; - private_data->tomcat_cmd_line = NULL; - private_data->tomcat_classpath = NULL; - private_data->jvm_dll_path = NULL; - private_data->tomcat_ms = 0; - private_data->tomcat_mx = 0; - private_data->sysprops = NULL; + _this->was_verified = JK_FALSE; + _this->was_initialized = JK_FALSE; + _this->jvm = NULL; + _this->tmp_env = NULL; + _this->jk_java_bridge_object = NULL; + _this->jk_java_bridge_class = NULL; + _this->jk_startup_method = NULL; + _this->jk_service_method = NULL; + _this->jk_shutdown_method = NULL; + _this->tomcat_cmd_line = NULL; + _this->tomcat_classpath = NULL; + _this->jvm_dll_path = NULL; + _this->tomcat_ms = 0; + _this->tomcat_mx = 0; + _this->sysprops = NULL; #ifdef JNI_VERSION_1_2 - private_data->java2opts = NULL; - private_data->java2lax = JK_TRUE; + _this->java2opts = NULL; + _this->java2lax = JK_TRUE; #endif - private_data->stdout_name = NULL; - private_data->stderr_name = NULL; + _this->stdout_name = NULL; + _this->stderr_name = NULL; - private_data->worker.worker_private = private_data; - private_data->worker.validate = validate; - private_data->worker.init = init; - private_data->worker.get_endpoint = get_endpoint; - private_data->worker.destroy = destroy; - - *result = &private_data->worker; - the_singleton_jni_worker = &private_data->worker; - private_data->worker.pool=pool; + _this->worker.worker_private = _this; + _this->worker.validate = validate; + _this->worker.init = init; + _this->worker.get_endpoint = get_endpoint; + _this->worker.destroy = destroy; + + *result = &_this->worker; + the_singleton_jni_worker = &_this->worker; + _this->worker.pool=pool; l->jkLog(l, JK_LOG_DEBUG, "Done jni_worker_factory\n"); return JK_TRUE; @@ -985,7 +993,7 @@ return vm_args.version; } -static char* build_opt_str(jk_pool_t *p, +static char* build_opt_str(jk_pool_t *pool, char* opt_name, char* opt_value, jk_logger_t *l) @@ -993,7 +1001,7 @@ unsigned len = strlen(opt_name) + strlen(opt_value) + 2; /* [V] IMHO, these should not be deallocated as long as the JVM runs */ - char *tmp = p->alloc(p, len); + char *tmp = pool->alloc(pool, len); if(tmp) { sprintf(tmp, "%s%s", opt_name, opt_value); @@ -1005,7 +1013,7 @@ } } -static char* build_opt_int(jk_pool_t *p, +static char* build_opt_int(jk_pool_t *pool, char* opt_name, int opt_value, jk_logger_t *l) @@ -1013,7 +1021,7 @@ /* [V] this should suffice even for 64-bit int */ unsigned len = strlen(opt_name) + 20 + 2; /* [V] IMHO, these should not be deallocated as long as the JVM runs */ - char *tmp = p->alloc(p, len); + char *tmp = pool->alloc(pool, len); if(tmp) { sprintf(tmp, "%s%d", opt_name, opt_value); 1.2 +4 -4 jakarta-tomcat-connectors/jk/native2/common/jk_msg_ajp.c Index: jk_msg_ajp.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_msg_ajp.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- jk_msg_ajp.c 2001/12/12 21:23:57 1.1 +++ jk_msg_ajp.c 2001/12/12 23:36:01 1.2 @@ -60,7 +60,7 @@ * Author: Costin Manolache * Author: Gal Shachor <[EMAIL PROTECTED]> * * Author: Henri Gomez <[EMAIL PROTECTED]> * - * Version: $Revision: 1.1 $ * + * Version: $Revision: 1.2 $ * ***************************************************************************/ #include "jk_pool.h" @@ -454,17 +454,17 @@ } -jk_msg_t *jk_msg_ajp_create(jk_pool_t *p, jk_logger_t *log, int buffSize) +jk_msg_t *jk_msg_ajp_create(jk_pool_t *pool, jk_logger_t *log, int buffSize) { jk_msg_t *msg = - (jk_msg_t *)p->calloc(p, sizeof(jk_msg_t)); + (jk_msg_t *)pool->calloc(pool, sizeof(jk_msg_t)); if( buffSize==0 ) buffSize=DEF_BUFFER_SZ; if(!msg) { return NULL; } - msg->pool = p; + msg->pool = pool; msg->buf= (unsigned char *)msg->pool->alloc(msg->pool, buffSize); 1.9 +2 -2 jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c Index: jk_uriMap.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_uriMap.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- jk_uriMap.c 2001/12/12 21:56:43 1.8 +++ jk_uriMap.c 2001/12/12 23:36:01 1.9 @@ -67,7 +67,7 @@ * servlet container. * * Author: Gal Shachor <[EMAIL PROTECTED]> - * Version: $Revision: 1.8 $ + * Version: $Revision: 1.9 $ */ #include "jk_pool.h" @@ -552,7 +552,7 @@ jk_map_t *init_data; jk_logger_t *l=env->logger; - _this = (jk_uriMap_t *)calloc(1,sizeof(jk_uriMap_t)); + _this = (jk_uriMap_t *)pool->calloc(pool, sizeof(jk_uriMap_t)); if( ! _this) { l->jkLog(l, JK_LOG_ERROR, "uriMap.factory() OutOfMemoryError\n"); return JK_FALSE; 1.7 +2 -1 jakarta-tomcat-connectors/jk/native2/common/jk_workerEnv.c Index: jk_workerEnv.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_workerEnv.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- jk_workerEnv.c 2001/12/12 21:36:17 1.6 +++ jk_workerEnv.c 2001/12/12 23:36:01 1.7 @@ -59,7 +59,7 @@ * Description: Workers controller * * Author: Gal Shachor <[EMAIL PROTECTED]> * * Author: Henri Gomez <[EMAIL PROTECTED]> * - * Version: $Revision: 1.6 $ * + * Version: $Revision: 1.7 $ * ***************************************************************************/ #include "jk_workerEnv.h" @@ -72,6 +72,7 @@ const char *type, const char *name); static void jk_workerEnv_close(jk_workerEnv_t *_this); +static void jk_workerEnv_initHandlers(jk_workerEnv_t *_this); /** * Init the workers, prepare the we. 1.6 +1 -1 jakarta-tomcat-connectors/jk/native2/server/apache2/jk_logger_apache2.c Index: jk_logger_apache2.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/server/apache2/jk_logger_apache2.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- jk_logger_apache2.c 2001/12/07 23:07:24 1.5 +++ jk_logger_apache2.c 2001/12/12 23:36:01 1.6 @@ -170,7 +170,7 @@ char *type, char *name) { - jk_logger_t *l = (jk_logger_t *)malloc(sizeof(jk_logger_t)); + jk_logger_t *l = (jk_logger_t *)pool->calloc(pool, sizeof(jk_logger_t)); if(l==NULL ) { return JK_FALSE;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>