From: <svn...@op...> - 2010-02-19 18:02:28
|
Author: scriptor Date: Fri Feb 19 19:02:10 2010 New Revision: 6038 URL: http://www.opensync.org/changeset/6038 Log: - Add missing osync_trace() call. - Removed a few leaks. - Cosmetic changes. Modified: plugins/ldap-sync/src/ldap_format.c plugins/ldap-sync/src/ldap_plugin.c Modified: plugins/ldap-sync/src/ldap_format.c ============================================================================== --- plugins/ldap-sync/src/ldap_format.c Thu Feb 11 01:53:31 2010 (r6037) +++ plugins/ldap-sync/src/ldap_format.c Fri Feb 19 19:02:10 2010 (r6038) @@ -1361,7 +1361,6 @@ osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason.\n"); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - return FALSE; } @@ -1958,8 +1957,8 @@ * user_data_carrier struct which stores references to memory * that has been allocated, but not freed, yet. * - * @param user_data Pointer to a user_data_carrier struct, that has - * allocated by ldap_format_finalize_converter(). + * @param user_data Pointer to a user_data_carrier struct, that has been + * allocated by ldap_format_initialize_converter(). * @param error The libopensync error pointer. * * @returns TRUE on success, FALSE otherwise. @@ -1986,10 +1985,12 @@ } + // http://xmlsoft.org/XSLT/html/libxslt-xslt.html#xsltCleanupGlobals // http://localhost/usr_share_doc/libxslt-devel-1.1.26/html/libxslt-xslt.html#xsltCleanupGlobals xsltCleanupGlobals(); + // http://xmlsoft.org/html/libxml-parser.html#xmlCleanupParser // http://localhost/usr_share_doc/libxml2-devel-2.7.6/html/libxml-parser.html#xmlCleanupParser /* * "This function name is somewhat misleading. It does not clean up @@ -2157,6 +2158,7 @@ xmlSchemaPtr xsd = NULL; xmlSchemaParserCtxtPtr xsd_file = NULL; + osync_trace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p)", __func__, (void *)input, inpsize, (void *)xmlcard, (void *)stylesheet_file, (void *)error); @@ -2912,6 +2914,7 @@ * the problem, that libxml2 may or may not free some cur->node * pointers: * + * http://xmlsoft.org/html/libxml-tree.html#xmlAddChild * Quoting from http://localhost/usr_share_doc/libxml2-devel-2.7.6/html/libxml-tree.html * * Function: xmlAddChild @@ -3597,9 +3600,6 @@ osync_bool ldap_format_do_convert_ldap2xmlinternal_create_head(const char *objtype, const char *ldap_format_name, xmlDoc **doc, xmlNode **root_node, OSyncError **error) { - - - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, (void *)objtype, (void *)ldap_format_name, (void *)doc, (void *)error); @@ -5443,9 +5443,9 @@ pre_output = NULL; } - // if (xmlformat) { - // osync_xmlformat_unref(xmlformat); - // } + if (xmlformat) { + osync_xmlformat_unref(xmlformat); + } osync_trace(TRACE_EXIT, "%s(): *ldap_entries = %p", __func__, (void *) *ldap_entries); @@ -5463,9 +5463,9 @@ pre_output = NULL; } - // if (xmlformat) { - // osync_xmlformat_unref(xmlformat); - // } + if (xmlformat) { + osync_xmlformat_unref(xmlformat); + } if (!osync_error_is_set(error)) Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Thu Feb 11 01:53:31 2010 (r6037) +++ plugins/ldap-sync/src/ldap_plugin.c Fri Feb 19 19:02:10 2010 (r6038) @@ -653,6 +653,17 @@ return TRUE; error: + // Clean up + if (path_field) { + g_free(path_field); + path_field = NULL; + } + + if (timestamp) { + g_free(timestamp); + timestamp = NULL; + } + if (!osync_error_is_set(error)) osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason.\n"); @@ -1756,34 +1767,27 @@ OSyncHashTable *hashtable = NULL; - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, (void *)ctx, (void *)info, (void *)sinkenv, (void *)error); - - if (ctx == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ctx = NULL.", __FILE__, __LINE__); goto error; } - if (sinkenv == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: sinkenv = NULL.", __FILE__, __LINE__); goto error; } - if (info == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: info = NULL.", __FILE__, __LINE__); goto error; } - if (!sinkenv->sink) { osync_trace(TRACE_INTERNAL, "%s:%i: INFO: No sink available. Apparently, this objtype has been disabled by configuration. Returning.\n", __FILE__, __LINE__); - osync_trace(TRACE_EXIT, "%s", __func__); - return TRUE; + goto out; } @@ -1797,7 +1801,6 @@ OSyncChange *change = osync_change_new(error); if (!change) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: change = NULL.\n", __FILE__, __LINE__); - osync_list_free(uids); goto error; } @@ -1809,6 +1812,7 @@ formatenv = osync_plugin_info_get_format_env(info); if (formatenv == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: formatenv = NULL. Returning.\n", __FILE__, __LINE__); + osync_change_unref(change); goto error; } @@ -1823,6 +1827,7 @@ OSyncObjFormat *format = sinkenv->objformat; if (format == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: format = NULL.\n", __FILE__, __LINE__); + osync_change_unref(change); goto error; } @@ -1836,6 +1841,7 @@ if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: odata = NULL.\n", __FILE__, __LINE__); } + osync_change_unref(change); goto error; } @@ -1857,12 +1863,21 @@ // end of OSYNC_CHANGE_TYPE_DELETED - osync_list_free(uids); - + if (uids) { + osync_list_free(uids); + uids = NULL; + } + +out: osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: + if (uids) { + osync_list_free(uids); + uids = NULL; + } + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; } @@ -1985,9 +2000,9 @@ { ldap_entry *ldapdata = NULL; unsigned int i = 0; - // unsigned int j = 0; + osync_trace(TRACE_ENTRY, "%s(%p, %p, %d, %p, %p)", __func__, (void *)ctx, (void *)sinkenv, slow_sync_requested, (void *)ldaplist_modified, (void *)error); if (ctx == NULL) { @@ -2000,17 +2015,14 @@ goto error; } - if (ldaplist_modified == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldaplist_modified = NULL.", __FILE__, __LINE__); goto error; } - if (!sinkenv->sink) { osync_trace(TRACE_INTERNAL, "%s:%i: INFO: No sink available. Apparently, this objtype has been disabled by configuration. Returning.\n", __FILE__, __LINE__); - osync_trace(TRACE_EXIT, "%s", __func__); - return TRUE; + goto out; } @@ -2046,7 +2058,7 @@ } // for (i = 0; i < g_list_length(ldaplist_modified) ; i++) - +out: osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; @@ -2060,6 +2072,9 @@ } + + + /** * @brief Tells the opensync library which LDAP entries have been deleted * on the LDAP server. Currently not used. @@ -2177,8 +2192,6 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %d, %p, %p)", __func__, (void *)ctx, (void *)sinkenv, slow_sync_requested, (void *)unmodified_uids, (void *)error); - - if (ctx == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ctx = NULL.", __FILE__, __LINE__); goto error; @@ -2189,30 +2202,24 @@ goto error; } - if (unmodified_uids == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: unmodified_uids = NULL.", __FILE__, __LINE__); goto error; } - if (!sinkenv->sink) { osync_trace(TRACE_INTERNAL, "%s:%i: INFO: No sink available. Apparently, this objtype has been disabled by configuration. Returning.\n", __FILE__, __LINE__); - osync_trace(TRACE_EXIT, "%s", __func__); - return TRUE; + goto out; } + + // Get Hashtable hashtable = osync_objtype_sink_get_hashtable(sinkenv->sink); osync_assert(hashtable); - if (unmodified_uids == NULL) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: unmodified_uids = NULL.\n", __FILE__, __LINE__); - goto error; - } - - + // Walk through the list for (list = g_list_first(unmodified_uids); list; list = g_list_next(list)) { OSyncChange *change = osync_change_new(error); @@ -2232,9 +2239,10 @@ osync_hashtable_update_change(hashtable, change); osync_change_unref(change); - } + } // for (list = g_list_first(unmodified_uids); +out: osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; @@ -2463,35 +2471,27 @@ goto error; } - if (info == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: info = NULL. Returning.\n", __FILE__, __LINE__); goto error; } - if (ctx == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ctx = NULL. Returning.\n", __FILE__, __LINE__); goto error; } - if (sink == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: sink = NULL. Returning.\n", __FILE__, __LINE__); goto error; } - - - - osync_trace(TRACE_INTERNAL, "%s:%i:%s(): Is this sink (%s) enabled? %d", __FILE__, __LINE__, __func__, osync_objtype_sink_get_name(sink), osync_objtype_sink_is_enabled(sink)); + osync_trace(TRACE_INTERNAL, "%s:%i:%s(): Is this sink (%s) enabled (1)? %d", __FILE__, __LINE__, __func__, osync_objtype_sink_get_name(sink), osync_objtype_sink_is_enabled(sink)); if (!osync_objtype_sink_is_enabled(sink)) { osync_trace(TRACE_INTERNAL, "%s:%i: Objtype \"%s\" has been disabled. So nothing to do. Early return.", __FILE__, __LINE__, osync_objtype_sink_get_name(sink)); - osync_context_report_success(ctx); // ldap_plugin_get_changes() - osync_trace(TRACE_EXIT, "%s", __func__); - return; + goto out; } @@ -2502,7 +2502,6 @@ goto error; } - if (sinkenv == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: sinkenv = NULL. Returning.\n", __FILE__, __LINE__); goto error; @@ -2519,17 +2518,13 @@ osync_trace(TRACE_INTERNAL, "sink = %p", (void *)sink); osync_trace(TRACE_INTERNAL, "sinkenv->sink = %p", (void *)(sinkenv->sink)); if (sinkenv->sink) { - osync_trace(TRACE_INTERNAL, "%s: Is this sink (%s) enabled? %d", __func__, osync_objtype_sink_get_name(sinkenv->sink), osync_objtype_sink_is_enabled(sinkenv->sink)); + osync_trace(TRACE_INTERNAL, "%s: Is this sink (%s) enabled (2)? %d", __func__, osync_objtype_sink_get_name(sinkenv->sink), osync_objtype_sink_is_enabled(sinkenv->sink)); } - - // Check read permission if (!(sinkenv->ldap_read)) { - osync_trace(TRACE_INTERNAL, "Reading entries from LDAP has been disabled by configuration"); - osync_context_report_success(ctx); // ldap_plugin_get_changes() - osync_trace(TRACE_EXIT, "%s", __func__); - return; + osync_trace(TRACE_INTERNAL, "Reading entries from LDAP has been disabled by configuration. So nothing to do here. Early return."); + goto out; // Nothing to do here. } @@ -2554,9 +2549,6 @@ - - - // Report all the changes that are to be added: if (ldaplist_added) { if (!ldap_plugin_report_changes_to_be_added(ctx, sinkenv, slow_sync_requested, ldaplist_added, &error)) { @@ -2568,9 +2560,9 @@ * Maybe in the destroy function ldap_format_destroy_format1() * But even this seems to be to early. */ - } + // Report all the changes that are to be modified: if (ldaplist_modified) { if (!ldap_plugin_report_changes_to_be_modified(ctx, sinkenv, slow_sync_requested, ldaplist_modified, &error)) { @@ -2584,6 +2576,7 @@ */ } + /** * Report all the changes that are to be removed from the hashtable. * Quoting from http://www.opensync.org/doxygen/group__OSyncHashtableAPI.html @@ -2592,19 +2585,17 @@ * not reported as osync_hashtable_update_change(), independent of the * changetype." */ + + // xxx jl: TODO ??????????? + // I don't report here anything??? + + + + // Report everything that does NOT need to be modified: if (unmodified_uids) { if (!ldap_plugin_report_changes_to_be_kept_being_unmodified(ctx, sinkenv, slow_sync_requested, unmodified_uids, &error)) { goto error; - } - - - for (list = g_list_first(unmodified_uids); list; list = g_list_next(list)) - { - if (list->data) { - g_free(list->data); - } - } - g_list_free(unmodified_uids); + } } @@ -2617,9 +2608,25 @@ //When you are done looping and if you are using hashtables //check for deleted entries ... via hashtable + // xxx jl: TODO ????? deleted_uids is not even passed on... ????? // This seems to be for entries that have already been deleted // on the peer, only. - ldap_plugin_process_deleted_entries(ctx, info, sinkenv, &error); + if (!ldap_plugin_process_deleted_entries(ctx, info, sinkenv, &error)) { + goto error; + } + + + // Clean up: + if (unmodified_uids) { + for (list = g_list_first(unmodified_uids); list; list = g_list_next(list)) + { + if (list->data) { + g_free(list->data); + } + } + g_list_free(unmodified_uids); + unmodified_uids = NULL; + } if (deleted_uids) { @@ -2633,7 +2640,7 @@ } - +out: //Now we need to answer the call osync_context_report_success(ctx); // ldap_plugin_get_changes() osync_trace(TRACE_EXIT, "%s", __func__); @@ -2653,6 +2660,18 @@ } + if (unmodified_uids) { + for (list = g_list_first(unmodified_uids); list; list = g_list_next(list)) + { + if (list->data) { + g_free(list->data); + } + } + g_list_free(unmodified_uids); + unmodified_uids = NULL; + } + + if (deleted_uids) { for (list = g_list_first(deleted_uids); list; list = g_list_next(list)) { @@ -4869,7 +4888,7 @@ if (!osync_error_is_set(error)) osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason"); - osync_trace(TRACE_INTERNAL, "%s(): return -2;", __func__); + osync_trace(TRACE_INTERNAL, "%s(): return -1;", __func__); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return -1; } |