示例#1
0
文件: tee.c 项目: jhnwkmn/MaxScale
/**
 * Free the memory associated with the session
 *
 * @param instance	The filter instance
 * @param session	The filter session
 */
static void
freeSession(FILTER *instance, void *session)
{
TEE_SESSION	*my_session = (TEE_SESSION *)session;
SESSION*	ses = my_session->branch_session;
session_state_t state;
#ifdef SS_DEBUG
skygw_log_write(LOGFILE_TRACE,"Tee free: %d", atomic_add(&debug_seq,1));
#endif
	if (ses != NULL)
	{
            state = ses->state;
            
		if (state == SESSION_STATE_ROUTER_READY)
		{
			session_free(ses);
		}
                else if (state == SESSION_STATE_TO_BE_FREED)
		{
			/** Free branch router session */
			ses->service->router->freeSession(
				ses->service->router_instance,
				ses->router_session);
			/** Free memory of branch client session */
			ses->state = SESSION_STATE_FREE;
			free(ses);
			/** This indicates that branch session is not available anymore */
			my_session->branch_session = NULL;
		}
                else if(state == SESSION_STATE_STOPPING)
                {
                    orphan_session_t* orphan;
                    if((orphan = malloc(sizeof(orphan_session_t))) == NULL)
                    {
                        skygw_log_write(LOGFILE_ERROR,"Error : Failed to "
                                "allocate memory for orphan session struct, "
                                "child session might leak memory.");
                    }else{
                        orphan->session = ses;
                        spinlock_acquire(&orphanLock);
                        orphan->next = allOrphans;
                        allOrphans = orphan;
                        spinlock_release(&orphanLock);
                    }
                }
	}
	if (my_session->dummy_filterdef)
	{
		filter_free(my_session->dummy_filterdef);
	}
        if(my_session->tee_replybuf)
            gwbuf_free(my_session->tee_replybuf);
	free(session);
        
	orphan_free(NULL);

        return;
}
示例#2
0
文件: tee.c 项目: DBMSRmutl/MaxScale
/**
 * Free the memory associated with the session
 *
 * @param instance	The filter instance
 * @param session	The filter session
 */
static void
freeSession(FILTER *instance, void *session)
{
    TEE_SESSION *my_session = (TEE_SESSION *) session;
    SESSION* ses = my_session->branch_session;
    session_state_t state;
#ifdef SS_DEBUG
    MXS_INFO("Tee free: %d", atomic_add(&debug_seq, 1));
#endif
    if (ses != NULL)
    {
        state = ses->state;

        if (state == SESSION_STATE_ROUTER_READY)
        {
            session_free(ses);
        }
        else if (state == SESSION_STATE_TO_BE_FREED)
        {
            /** Free branch router session */
            ses->service->router->freeSession(
                                              ses->service->router_instance,
                                              ses->router_session);
            /** Free memory of branch client session */
            ses->state = SESSION_STATE_FREE;
            free(ses);
            /** This indicates that branch session is not available anymore */
            my_session->branch_session = NULL;
        }
        else if (state == SESSION_STATE_STOPPING)
        {
            create_orphan(ses);
        }
    }
    if (my_session->dummy_filterdef)
    {
        filter_free(my_session->dummy_filterdef);
    }
    if (my_session->tee_replybuf)
    {
        gwbuf_free(my_session->tee_replybuf);
    }
    free(session);

    orphan_free(NULL);

    return;
}