If adding an IMC/IMV fails, terminate() it only if it has been initialize()d
authorMartin Willi <martin@revosec.ch>
Wed, 14 Nov 2012 15:17:57 +0000 (16:17 +0100)
committerMartin Willi <martin@revosec.ch>
Fri, 30 Nov 2012 14:48:13 +0000 (15:48 +0100)
src/libcharon/plugins/tnc_imc/tnc_imc_manager.c
src/libcharon/plugins/tnc_imv/tnc_imv_manager.c

index bc929b8..1d2cd0c 100644 (file)
@@ -51,10 +51,9 @@ METHOD(imc_manager_t, add, bool,
 {
        TNC_Version version;
 
-       /* Initialize the module */
        imc->set_id(imc, this->next_imc_id);
        if (imc->initialize(imc->get_id(imc), TNC_IFIMC_VERSION_1,
-                       TNC_IFIMC_VERSION_1, &version) != TNC_RESULT_SUCCESS)
+                                               TNC_IFIMC_VERSION_1, &version) != TNC_RESULT_SUCCESS)
        {
                DBG1(DBG_TNC, "IMC \"%s\" failed to initialize", imc->get_name(imc));
                return FALSE;
@@ -62,15 +61,18 @@ METHOD(imc_manager_t, add, bool,
        this->imcs->insert_last(this->imcs, imc);
        this->next_imc_id++;
 
-       if (imc->provide_bind_function(imc->get_id(imc), TNC_TNCC_BindFunction)
-                       != TNC_RESULT_SUCCESS)
+       if (imc->provide_bind_function(imc->get_id(imc),
+                                                                  TNC_TNCC_BindFunction) != TNC_RESULT_SUCCESS)
        {
+               if (imc->terminate)
+               {
+                       imc->terminate(imc->get_id(imc));
+               }
                DBG1(DBG_TNC, "IMC \"%s\" failed to obtain bind function",
-                                          imc->get_name(imc));
+                        imc->get_name(imc));
                this->imcs->remove_last(this->imcs, (void**)&imc);
                return FALSE;
        }
-
        return TRUE;
 }
 
@@ -107,12 +109,6 @@ METHOD(imc_manager_t, load, bool,
        }
        if (!add(this, imc))
        {
-               if (imc->terminate &&
-                       imc->terminate(imc->get_id(imc)) != TNC_RESULT_SUCCESS)
-               {
-                       DBG1(DBG_TNC, "IMC \"%s\" not terminated successfully",
-                                                  imc->get_name(imc));
-               }
                imc->destroy(imc);
                return FALSE;
        }
index a8c0c03..c5bb5ff 100644 (file)
@@ -67,10 +67,9 @@ METHOD(imv_manager_t, add, bool,
 {
        TNC_Version version;
 
-       /* Initialize the IMV module */
        imv->set_id(imv, this->next_imv_id);
        if (imv->initialize(imv->get_id(imv), TNC_IFIMV_VERSION_1,
-               TNC_IFIMV_VERSION_1, &version) != TNC_RESULT_SUCCESS)
+                                               TNC_IFIMV_VERSION_1, &version) != TNC_RESULT_SUCCESS)
        {
                DBG1(DBG_TNC, "IMV \"%s\" failed to initialize", imv->get_name(imv));
                return FALSE;
@@ -78,15 +77,18 @@ METHOD(imv_manager_t, add, bool,
        this->imvs->insert_last(this->imvs, imv);
        this->next_imv_id++;
 
-       if (imv->provide_bind_function(imv->get_id(imv), TNC_TNCS_BindFunction)
-                       != TNC_RESULT_SUCCESS)
+       if (imv->provide_bind_function(imv->get_id(imv),
+                                                                  TNC_TNCS_BindFunction) != TNC_RESULT_SUCCESS)
        {
-               DBG1(DBG_TNC, "IMV \"%s\" could failed to obtain bind function",
-                                          imv->get_name(imv));
+               if (imv->terminate)
+               {
+                       imv->terminate(imv->get_id(imv));
+               }
+               DBG1(DBG_TNC, "IMV \"%s\" failed to obtain bind function",
+                        imv->get_name(imv));
                this->imvs->remove_last(this->imvs, (void**)&imv);
                return FALSE;
        }
-
        return TRUE;
 }
 
@@ -123,12 +125,6 @@ METHOD(imv_manager_t, load, bool,
        }
        if (!add(this, imv))
        {
-               if (imv->terminate &&
-                       imv->terminate(imv->get_id(imv)) != TNC_RESULT_SUCCESS)
-               {
-                       DBG1(DBG_TNC, "IMV \"%s\" not terminated successfully",
-                                                  imv->get_name(imv));
-               }
                imv->destroy(imv);
                return FALSE;
        }