static VECTOR_HANDLE VECTOR_copy(VECTOR_HANDLE vector)
{
    VECTOR_HANDLE new_vector = VECTOR_create(sizeof(STRING_HANDLE));

    size_t size = VECTOR_size(vector);
    for (size_t index = 0; index < size && new_vector != NULL; index++)
    {
        STRING_HANDLE* str = VECTOR_element(vector, index);
        if (str == NULL)
        {
            VECTOR_destroy(new_vector);
            new_vector = NULL;
        }
        else
        {
            STRING_HANDLE new_str = STRING_clone(*str);
            if (new_str == NULL)
            {
                VECTOR_destroy(new_vector);
                new_vector = NULL;
            }
            else
            {
                if (VECTOR_push_back(new_vector, &new_str, 1) != 0)
                {
                    STRING_delete(new_str);
                    VECTOR_destroy(new_vector);
                    new_vector = NULL;
                }
            }
        }
    }

    return new_vector;
}
static JVM_OPTIONS* options_copy(JVM_OPTIONS* options)
{
    //Copy the VECTOR_HANDLE
    JVM_OPTIONS* new_options = (JVM_OPTIONS*)malloc(sizeof(JVM_OPTIONS));
    if (new_options == NULL)
    {
        LogError("Failed to allocate memory for JVM_OPTIONS structure.");
    }
    else
    {
        new_options->additional_options = NULL;
        if (options->additional_options != NULL)
        {
            new_options->additional_options = VECTOR_copy(options->additional_options);
        }

        if (options->additional_options != NULL && new_options->additional_options == NULL)
        {
            LogError("Failed to copy additional_options VECTOR_HANDLE.");
            free(new_options);
            new_options = NULL;
        }
        else
        {
            //Copy the class path
            int status = mallocAndStrcpy_s((char**)(&new_options->class_path), options->class_path);
            if (status != 0)
            {
                LogError("Failed to allocate class_path.");
                VECTOR_destroy(new_options->additional_options);
                free(new_options);
                new_options = NULL;
            }
            else
            {
                //Copy the library path
                status = mallocAndStrcpy_s((char**)(&new_options->library_path), options->library_path);
                if (status != 0)
                {
                    LogError("Failed to allocate library_path.");
                    free((void*)new_options->class_path);
                    VECTOR_destroy(new_options->additional_options);
                    free(new_options);
                    new_options = NULL;
                }
                else
                {
                    new_options->debug = options->debug;
                    new_options->debug_port = options->debug_port;
                    new_options->verbose = options->verbose;
                    new_options->version = options->version;
                }
            }
        }
    }
    return new_options;
}
Exemplo n.º 3
0
void HTTPAPIEX_Destroy(HTTPAPIEX_HANDLE handle)
{
    if (handle != NULL)
    {
        /*Codes_SRS_HTTPAPIEX_02_042: [HTTPAPIEX_Destroy shall free all the resources used by HTTAPIEX_HANDLE.]*/
        size_t i;
        size_t vectorSize;
        HTTPAPIEX_HANDLE_DATA* handleData = (HTTPAPIEX_HANDLE_DATA*)handle;
        
        if (handleData->k == 2)
        {
            HTTPAPI_CloseConnection(handleData->httpHandle);
            HTTPAPI_Deinit();
        }
        STRING_delete(handleData->hostName);

        vectorSize = VECTOR_size(handleData->savedOptions);
        for (i = 0; i < vectorSize; i++)
        {
            HTTPAPIEX_SAVED_OPTION*savedOption = VECTOR_element(handleData->savedOptions, i);
            free((void*)savedOption->optionName);
            free((void*)savedOption->value);
        }
        VECTOR_destroy(handleData->savedOptions);

        free(handle);
    }
    else
    {
        /*Codes_SRS_HTTPAPIEX_02_043: [If parameter handle is NULL then HTTPAPIEX_Destroy shall take no action.] */
    }
}
Exemplo n.º 4
0
void DataPublisher_DestroyTransaction_ReportedProperties(REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle)
{
    /*Codes_SRS_DATA_PUBLISHER_02_025: [ If argument transactionHandle is NULL then DataPublisher_DestroyTransaction_ReportedProperties shall return. ]*/
    if (transactionHandle == NULL)
    {
        LogError("invalig argument REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle=%p", transactionHandle);
    }
    else
    {
        /*Codes_SRS_DATA_PUBLISHER_02_026: [ Otherwise DataPublisher_DestroyTransaction_ReportedProperties shall free all resources associated with the reported properties transactionHandle. ]*/
        REPORTED_PROPERTIES_TRANSACTION_HANDLE_DATA* handleData = (REPORTED_PROPERTIES_TRANSACTION_HANDLE_DATA*)transactionHandle;
        size_t i, nReportedProperties;
        nReportedProperties = VECTOR_size(handleData->value);
        for (i = 0;i < nReportedProperties;i++)
        {
            DATA_MARSHALLER_VALUE *value = *(DATA_MARSHALLER_VALUE**)VECTOR_element(handleData->value, i);
            Destroy_AGENT_DATA_TYPE((AGENT_DATA_TYPE*)value->Value);
            free((void*)value->Value);
            free((void*)value->PropertyPath);
            free((void*)value);
        }
        VECTOR_destroy(handleData->value);
        free(handleData);
    }
    return;
}
void IoTHubTransport_Destroy(TRANSPORT_HANDLE transportHlHandle)
{
	/*Codes_SRS_IOTHUBTRANSPORT_17_011: [ IoTHubTransport_Destroy shall do nothing if transportHlHandle is NULL. ]*/
	if (transportHlHandle != NULL)
	{
		TRANSPORT_HANDLE_DATA * transportData = (TRANSPORT_HANDLE_DATA*)transportHlHandle;
		/*Codes_SRS_IOTHUBTRANSPORT_17_033: [ IoTHubTransport_Destroy shall lock the transport lock. ]*/
		if (Lock(transportData->lockHandle) != LOCK_OK)
		{
			LogError("Unable to lock - will still attempt to end thread without thread safety");
			stop_worker_thread(transportData);
		}
		else
		{
			stop_worker_thread(transportData);
			(void)Unlock(transportData->lockHandle);
		}
		wait_worker_thread(transportData);
		/*Codes_SRS_IOTHUBTRANSPORT_17_010: [ IoTHubTransport_Destroy shall free all resources. ]*/
		Lock_Deinit(transportData->lockHandle);
		(transportData->IoTHubTransport_Destroy)(transportData->transportLLHandle);
		VECTOR_destroy(transportData->clients);
		free(transportHlHandle);
	}
}
void ModuleLoader_Destroy(void)
{
    if (g_module_loaders.lock != NULL)
    {
        if (Lock(g_module_loaders.lock) != LOCK_OK)
        {
            LogError("Lock failed. Proceeding with destruction anyway.");
        }
    }
    if(g_module_loaders.module_loaders != NULL)
    {
        // free all module loader resources
        size_t length = VECTOR_size(g_module_loaders.module_loaders);
        for (size_t i = 0; i < length; i++)
        {
            MODULE_LOADER* loader = *((MODULE_LOADER **)VECTOR_element(g_module_loaders.module_loaders, i));

            // NOTE: We free the configuration object even for default loaders because
            // the configuration may have been replaced by the gateway for default
            // loaders.

            /*Codes_SRS_MODULE_LOADER_13_046: [ ModuleLoader_Destroy shall invoke FreeConfiguration on every module loader's configuration field. ]*/
            if (loader->configuration != NULL)
            {
                loader->api->FreeConfiguration(loader, loader->configuration);
            }

            // if this is not a default loader then free resources allocated in
            // add_loader_from_json
            if (ModuleLoader_IsDefaultLoader(loader->name) == false)
            {
                /*Codes_SRS_MODULE_LOADER_13_047: [ ModuleLoader_Destroy shall free the loader's name and the loader itself if it is not a default loader. ]*/
                free((void *)loader->name);
                free(loader);
            }
        }

        /*Codes_SRS_MODULE_LOADER_13_048: [ ModuleLoader_Destroy shall destroy the loaders vector. ]*/
        VECTOR_destroy(g_module_loaders.module_loaders);
        g_module_loaders.module_loaders = NULL;
    }

    if (g_module_loaders.lock != NULL)
    {
        if (Unlock(g_module_loaders.lock) != LOCK_OK)
        {
            LogError("Unlock failed.");
        }

        /*Codes_SRS_MODULE_LOADER_13_045: [ ModuleLoader_Destroy shall free g_module_loaders.lock if it is not NULL. ]*/
        Lock_Deinit(g_module_loaders.lock);
        g_module_loaders.lock = NULL;
    }
}
static void config_destroy(JAVA_MODULE_HOST_CONFIG* config)
{
    free((void*)config->class_name);
    free((void*)config->configuration_json);
    if (config->options != NULL)
    {
        free((void*)config->options->class_path);
        free((void*)config->options->library_path);
        VECTOR_destroy(config->options->additional_options);
        free(config->options);
    }
    free(config);
}