From 7363ca8ab110b3e8e37bc6ec26bc7b985723a5ec Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 26 Oct 2011 16:05:56 -0400 Subject: [PATCH] Thanks to berick for making it clear that ctx->session->userData wasn't initialized yet Signed-off-by: Lebbeous Fogle-Weekley --- Open-ILS/src/c-apps/oils_sql.c | 62 ++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_sql.c b/Open-ILS/src/c-apps/oils_sql.c index af3ba0a19e..e1869e9eb7 100644 --- a/Open-ILS/src/c-apps/oils_sql.c +++ b/Open-ILS/src/c-apps/oils_sql.c @@ -510,7 +510,7 @@ void userDataFree( void* blob ) { that it will free whatever else needs freeing. */ static void sessionDataFree( char* key, void* item ) { - if( !strcmp( key, "xact_id" ) || !strcmp( key, "authkey" ) ) + if( !strcmp( key, "xact_id" ) || !strcmp( key, "authkey" ) || !strncmp( key, "rs_size_", 8) ) free( item ); else if( !strcmp( key, "user_login" ) ) jsonObjectFree( (jsonObject*) item ); @@ -523,6 +523,19 @@ static void pcacheFree( char* key, void* item ) { } /** + @brief Initialize session cache. + @param ctx Pointer to the method context. + + Create a cache for the session by making the session's userData member point + to an osrfHash instance. +*/ +static void initSessionCache( osrfMethodContext* ctx ) { + ctx->session->userData = osrfNewHash(); + osrfHashSetCallback( (osrfHash*) ctx->session->userData, &sessionDataFree ); + ctx->session->userDataFree = &userDataFree; +} + +/** @brief Save a transaction id. @param ctx Pointer to the method context. @@ -536,11 +549,8 @@ static void setXactId( osrfMethodContext* ctx ) { // If the session doesn't already have a hash, create one. Make sure // that the application session frees the hash when it terminates. - if( NULL == cache ) { - session->userData = cache = osrfNewHash(); - osrfHashSetCallback( cache, &sessionDataFree ); - ctx->session->userDataFree = &userDataFree; - } + if( NULL == cache ) + initSessionCache( ctx ); // Save the transaction id in the hash, with the key "xact_id" osrfHashSet( cache, strdup( session->session_id ), "xact_id" ); @@ -586,11 +596,8 @@ static void setPermLocationCache( osrfMethodContext* ctx, const char* perm, osrf // If the session doesn't already have a hash, create one. Make sure // that the application session frees the hash when it terminates. - if( NULL == cache ) { - session->userData = cache = osrfNewHash(); - osrfHashSetCallback( cache, &sessionDataFree ); - ctx->session->userDataFree = &userDataFree; - } + if( NULL == cache ) + initSessionCache( ctx ); osrfHash* pcache = osrfHashGet(cache, "pcache"); @@ -641,11 +648,8 @@ static void setUserLogin( osrfMethodContext* ctx, jsonObject* user_login ) { // If the session doesn't already have a hash, create one. Make sure // that the application session frees the hash when it terminates. - if( NULL == cache ) { - session->userData = cache = osrfNewHash(); - osrfHashSetCallback( cache, &sessionDataFree ); - ctx->session->userDataFree = &userDataFree; - } + if( NULL == cache ) + initSessionCache( ctx ); if( user_login ) osrfHashSet( cache, user_login, "user_login" ); @@ -683,11 +687,8 @@ static void setAuthkey( osrfMethodContext* ctx, const char* authkey ) { // If the session doesn't already have a hash, create one. Make sure // that the application session frees the hash when it terminates. - if( NULL == cache ) { - session->userData = cache = osrfNewHash(); - osrfHashSetCallback( cache, &sessionDataFree ); - ctx->session->userDataFree = &userDataFree; - } + if( NULL == cache ) + initSessionCache( ctx ); // Save the transaction id in the hash, with the key "xact_id" if( authkey && *authkey ) @@ -1431,7 +1432,7 @@ static int verifyObjectPCRUD ( osrfMethodContext* ctx, osrfHash *class, const js const char* method_type = osrfHashGet( method_metadata, "methodtype" ); if (!rs_size) { - int *rs_size_from_hash = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request ); + int *rs_size_from_hash = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "rs_size_req_%d", ctx->request ); if (rs_size_from_hash) { rs_size = *rs_size_from_hash; osrfLogDebug(OSRF_LOG_MARK, "used rs_size from request-scoped hash: %d", rs_size); @@ -5549,6 +5550,9 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_ char* pkey = osrfHashGet( class_meta, "primarykey" ); + if (!ctx->session->userData) + initSessionCache( ctx ); + char *inside_verify = osrfHashGet( (osrfHash*) ctx->session->userData, "inside_verify" ); int need_to_verify = 1; @@ -5619,19 +5623,13 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_ // 2. figure out one consistent rs_size for verifyObjectPCRUD to use // over the whole life of this request. This means if we've already set - // up a req_%d_rs_size, do nothing. - int *rs_size = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request ); + // up a rs_size_req_%d, do nothing. + int *rs_size = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "rs_size_req_%d", ctx->request ); if (!rs_size) { // pointer null, so value not set in hash - rs_size = (int *) safe_malloc( sizeof(int) ); + rs_size = (int *) safe_malloc( sizeof(int) ); // will be freed by sessionDataFree() unsigned long long result_count = dbi_result_get_numrows( result ); *rs_size = (int) result_count * (flesh_depth + 1); // yes, we could lose some bits, but come on - osrfLogDebug( OSRF_LOG_MARK, "about to set rs_size to %d", *rs_size ); - osrfHashSet( (osrfHash *) ctx->session->userData, rs_size, "req_%d_rs_size", ctx->request ); - int *rs_size_test = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "req_%d_rs_size", ctx->request ); - if (rs_size_test) - osrfLogDebug( OSRF_LOG_MARK, "immediately after set, get says rs_size is %d", *rs_size_test ); - else - osrfLogDebug( OSRF_LOG_MARK, "immediately after set, get says rs_size is NULL!" ); + osrfHashSet( (osrfHash *) ctx->session->userData, rs_size, "rs_size_req_%d", ctx->request ); } if( dbi_result_first_row( result )) { -- 2.11.0