Ticket #978: osync_plugin_env_free_removed.diff
| File osync_plugin_env_free_removed.diff, 6.2 KB (added by ianmartin, 3 years ago) |
|---|
-
wrapper/opensync-plugin.i
106 106 } 107 107 108 108 ~PluginEnv() { 109 osync_plugin_env_ free(self);109 osync_plugin_env_unref(self); 110 110 } 111 111 112 112 void load(const char *path = NULL) { -
opensync/plugin/opensync_plugin_env_private.h
27 27 GList *modules; 28 28 29 29 GModule *current_module; 30 31 int ref_count; 30 32 }; 31 33 32 34 #endif /* _OPENSYNC_PLUGIN_ENV_PRIVATE_H_ */ -
opensync/plugin/opensync_plugin_env.c
37 37 return NULL; 38 38 } 39 39 40 env->ref_count = 1; 40 41 osync_trace(TRACE_EXIT, "%s: %p", __func__, env); 41 42 return env; 42 43 } 43 44 44 void osync_plugin_env_free(OSyncPluginEnv *env) 45 46 OSyncPluginEnv *osync_plugin_env_ref(OSyncPluginEnv *env) 45 47 { 46 48 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env); 47 49 osync_assert(env); 50 51 g_atomic_int_inc(&(env->ref_count)); 52 53 osync_trace(TRACE_EXIT, "%s", __func__); 54 return env; 55 56 } 57 58 void osync_plugin_env_unref(OSyncPluginEnv *env) 59 { 60 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env); 61 osync_assert(env); 48 62 49 /* Free the plugins */ 50 while (env->plugins) { 51 osync_plugin_unref(env->plugins->data); 52 env->plugins = g_list_remove(env->plugins, env->plugins->data); 53 } 63 if (g_atomic_int_dec_and_test(&(env->ref_count))) { 64 /* Free the plugins */ 65 while (env->plugins) { 66 osync_plugin_unref(env->plugins->data); 67 env->plugins = g_list_remove(env->plugins, env->plugins->data); 68 } 54 69 55 /* Unload all modules */ 56 while (env->modules) { 57 osync_module_unload(env->modules->data); 58 osync_module_free(env->modules->data); 59 env->modules = g_list_remove(env->modules, env->modules->data); 70 /* Unload all modules */ 71 while (env->modules) { 72 osync_module_unload(env->modules->data); 73 osync_module_free(env->modules->data); 74 env->modules = g_list_remove(env->modules, env->modules->data); 75 } 76 osync_free(env); 60 77 } 61 78 62 g_free(env);63 64 79 osync_trace(TRACE_EXIT, "%s", __func__); 65 80 } 66 81 -
opensync/plugin/opensync_plugin_env.h
47 47 */ 48 48 OSYNC_EXPORT OSyncPluginEnv *osync_plugin_env_new(OSyncError **error); 49 49 50 /*! @brief Frees a osyncenvironment50 /*! @brief Increases the reference counton an opensync plugin environment 51 51 * 52 * Frees a osync environment and all resources. 52 * The reference count on the OSyncPluginEnv is incremented. When the 53 * reference is no longer needed it should be removed with 54 * osync_plugin_env_unref 53 55 * 54 * @ param env Pointer to the environment to free56 * @returns The environment passed in 55 57 * 56 58 */ 57 OSYNC_EXPORT void osync_plugin_env_free(OSyncPluginEnv *env);59 OSYNC_EXPORT OSyncPluginEnv *osync_plugin_env_ref(OSyncPluginEnv *env); 58 60 61 /*! @brief Removes a reference to an OSyncPluginEnv 62 * 63 * Decrements the reference count on an osync plugin environment. If 64 * the reference count reaches zero the environment is freed and all 65 * resources are unreferenced 66 * 67 * @param env Pointer to the environment to unreference 68 * 69 */ 70 OSYNC_EXPORT void osync_plugin_env_unref(OSyncPluginEnv *env); 71 59 72 /*! @brief Loads the sync modules from a given directory 60 73 * 61 74 * Loads all sync modules from a directory into a osync environment -
opensync/engine/opensync_engine.c
1301 1301 } 1302 1302 1303 1303 if (engine->pluginenv) { 1304 osync_plugin_env_ free(engine->pluginenv);1304 osync_plugin_env_unref(engine->pluginenv); 1305 1305 engine->pluginenv = NULL; 1306 1306 } 1307 1307 -
opensync/client/opensync_client.c
698 698 } 699 699 700 700 if (client->plugin_env) { 701 osync_plugin_env_ free(client->plugin_env);701 osync_plugin_env_unref(client->plugin_env); 702 702 client->plugin_env = NULL; 703 703 } 704 704 -
tools/osyncplugin.c
429 429 osync_format_env_free(format_env); 430 430 format_env = NULL; 431 431 error_free_pluginenv: 432 osync_plugin_env_ free(plugin_env);432 osync_plugin_env_unref(plugin_env); 433 433 plugin_env = NULL; 434 434 error: 435 435 return FALSE; … … 1218 1218 osync_format_env_free(format_env); 1219 1219 format_env = NULL; 1220 1220 error_free_pluginenv: 1221 osync_plugin_env_ free(plugin_env);1221 osync_plugin_env_unref(plugin_env); 1222 1222 plugin_env = NULL; 1223 1223 error: 1224 1224 return FALSE; … … 1255 1255 1256 1256 success: 1257 1257 if (plugin_env) 1258 osync_plugin_env_ free(plugin_env);1258 osync_plugin_env_unref(plugin_env); 1259 1259 1260 1260 for (o=cmdlist; o; o = o->next) { 1261 1261 Command *cmd = o->data; … … 1272 1272 finalize_plugin(&plugin_data); 1273 1273 //error_free_plugin_env: 1274 1274 if (plugin_env) 1275 osync_plugin_env_ free(plugin_env);1275 osync_plugin_env_unref(plugin_env); 1276 1276 1277 1277 for (o=cmdlist; o; o = o->next) { 1278 1278 Command *cmd = o->data; -
opensync.sym
561 561 osync_plugin_connection_usb_set_vendorid 562 562 osync_plugin_discover 563 563 osync_plugin_env_find_plugin 564 osync_plugin_env_free565 564 osync_plugin_env_load 566 565 osync_plugin_env_new 567 566 osync_plugin_env_nth_plugin 568 567 osync_plugin_env_num_plugins 569 568 osync_plugin_env_plugin_is_usable 569 osync_plugin_env_ref 570 570 osync_plugin_env_register_plugin 571 osync_plugin_env_unref 571 572 osync_plugin_finalize 572 573 osync_plugin_get_config_type 573 574 osync_plugin_get_data
