equal
deleted
inserted
replaced
1203 { |
1203 { |
1204 return (pk11_library_init(e)); |
1204 return (pk11_library_init(e)); |
1205 } |
1205 } |
1206 |
1206 |
1207 /* |
1207 /* |
|
1208 * Helper function that unsets reference to current engine (pk11_engine = NULL). |
|
1209 * |
|
1210 * Use of local variable only seems clumsy, it needs to be this way! |
|
1211 * This is to prevent double free in the unlucky scenario: |
|
1212 * ENGINE_free calls pk11_destroy calls pk11_finish calls ENGINE_free |
|
1213 * Setting pk11_engine to NULL prior to ENGINE_free() avoids this. |
|
1214 */ |
|
1215 static void pk11_engine_free() |
|
1216 { |
|
1217 ENGINE* old_engine = pk11_engine; |
|
1218 |
|
1219 if (old_engine) { |
|
1220 pk11_engine = NULL; |
|
1221 ENGINE_free(old_engine); |
|
1222 } |
|
1223 } |
|
1224 |
|
1225 /* |
1208 * Initialization function. Sets up various PKCS#11 library components. |
1226 * Initialization function. Sets up various PKCS#11 library components. |
1209 * It selects a slot based on predefined critiera. In the process, it also |
1227 * It selects a slot based on predefined critiera. In the process, it also |
1210 * count how many ciphers and digests to support. Since the cipher and |
1228 * count how many ciphers and digests to support. Since the cipher and |
1211 * digest information is needed when setting default engine, this function |
1229 * digest information is needed when setting default engine, this function |
1212 * needs to be called before calling ENGINE_set_default. |
1230 * needs to be called before calling ENGINE_set_default. |
1221 int any_slot_found; |
1239 int any_slot_found; |
1222 int i; |
1240 int i; |
1223 |
1241 |
1224 if (e != pk11_engine) |
1242 if (e != pk11_engine) |
1225 { |
1243 { |
1226 if (pk11_engine) |
1244 pk11_engine_free(); |
1227 ENGINE_free(pk11_engine); |
|
1228 pk11_engine = e; |
1245 pk11_engine = e; |
1229 ENGINE_up_ref(e); |
1246 ENGINE_up_ref(e); |
1230 } |
1247 } |
1231 |
1248 |
1232 /* |
1249 /* |
1471 } |
1488 } |
1472 pk11_dso = NULL; |
1489 pk11_dso = NULL; |
1473 pFuncList = NULL; |
1490 pFuncList = NULL; |
1474 pk11_library_initialized = CK_FALSE; |
1491 pk11_library_initialized = CK_FALSE; |
1475 pk11_pid = 0; |
1492 pk11_pid = 0; |
1476 ENGINE_free(pk11_engine); |
1493 pk11_engine_free(); |
1477 pk11_engine = NULL; |
|
1478 /* |
1494 /* |
1479 * There is no way how to unregister atfork handlers (other than |
1495 * There is no way how to unregister atfork handlers (other than |
1480 * unloading the library) so we just free the locks. For this reason |
1496 * unloading the library) so we just free the locks. For this reason |
1481 * the atfork handlers check if the engine is initialized and bail out |
1497 * the atfork handlers check if the engine is initialized and bail out |
1482 * immediately if not. This is necessary in case a process finishes |
1498 * immediately if not. This is necessary in case a process finishes |