From: <svn...@op...> - 2009-03-13 09:29:57
|
Author: bellmich Date: Fri Mar 13 10:29:53 2009 New Revision: 970 URL: http://libsyncml.opensync.org/changeset/970 Log: - added a missing SmlDevInf reference which causes a segmentation fault if a cached SmlDevInf object is used by OpenSync's SyncML plugin - smlDataSyncObjectUnref tries to cleanup the transport now more cleanly - fixed several comments - added some trace statements Modified: trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync.h trunk/libsyncml/data_sync_api/data_sync_devinf.c trunk/libsyncml/data_sync_api/standard.h trunk/libsyncml/sml_transport.c Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Tue Mar 10 14:35:23 2009 (r969) +++ trunk/libsyncml/data_sync_api/data_sync.c Fri Mar 13 10:29:53 2009 (r970) @@ -61,6 +61,7 @@ dsObject->tspType = tspType; dsObject->version = SML_VERSION_11; dsObject->sentChanges = FALSE; + dsObject->isInitialized = FALSE; dsObject->useNumberOfChanges = TRUE; dsObject->useTimestampAnchor = TRUE; @@ -526,6 +527,8 @@ if (!dsObject->funcDsInit(dsObject, error)) goto error; + dsObject->isInitialized = TRUE; + smlTrace(TRACE_EXIT, "%s - TRUE", __func__); return TRUE; error: @@ -825,8 +828,20 @@ /* cleanup transport */ if ((*dsObject)->tsp) { SmlError *error = NULL; - if (!smlTransportFinalize((*dsObject)->tsp, &error)) { - g_warning("%s: %s", __func__, smlErrorPrint(&error)); + if ((*dsObject)->dsType == SML_SESSION_TYPE_CLIENT && + (*dsObject)->isConnected && + !(*dsObject)->gotDisconnect && + !smlTransportDisconnect((*dsObject)->tsp, NULL, &error)) { + /* just ignore the error */ + smlTrace(TRACE_ERROR, "%s: %s", + __func__, smlErrorPrint(&error)); + smlErrorDeref(&error); + } + /* FIXME: we have to wait here for the disconnect ... */ + if ((*dsObject)->isInitialized && + !smlTransportFinalize((*dsObject)->tsp, &error)) { + smlTrace(TRACE_ERROR, "%s: %s", + __func__, smlErrorPrint(&error)); smlErrorDeref(&error); } smlTransportFree((*dsObject)->tsp); Modified: trunk/libsyncml/data_sync_api/data_sync.h ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.h Tue Mar 10 14:35:23 2009 (r969) +++ trunk/libsyncml/data_sync_api/data_sync.h Fri Mar 13 10:29:53 2009 (r970) @@ -147,6 +147,7 @@ /* states */ + SmlBool isInitialized; SmlBool isConnected; SmlBool gotDisconnect; SmlBool tryDisconnect; Modified: trunk/libsyncml/data_sync_api/data_sync_devinf.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_devinf.c Tue Mar 10 14:35:23 2009 (r969) +++ trunk/libsyncml/data_sync_api/data_sync_devinf.c Fri Mar 13 10:29:53 2009 (r970) @@ -565,10 +565,11 @@ SmlDataSyncObject *dsObject, SmlError **error) { + smlTrace(TRACE_ENTRY, "%s(%p,%p)", __func__, dsObject, error); CHECK_ERROR_REF smlAssert(dsObject); - /* if there is already a remote devine information + /* if there is already a remote device information * then cleanup the reference. */ if (dsObject->remoteDevInf) @@ -581,18 +582,22 @@ smlDevInfRef(dsObject->remoteDevInf); _update_session_config_from_devinf(dsObject); /* DevInf caching is optional */ - if (dsObject->writeDevInfCallback) + if (dsObject->writeDevInfCallback) { + smlTrace(TRACE_EXIT, "%s - calling writeDevInfCallback", __func__); return dsObject->writeDevInfCallback( dsObject, dsObject->remoteDevInf, dsObject->writeDevInfUserdata, error); - else + } else { + smlTrace(TRACE_EXIT, "%s - remote DevInf available", __func__); return TRUE; + } } else { smlTrace(TRACE_INTERNAL, "%s: The remote DevInf was not received.", __func__); /* DevInf caching is optional */ if (dsObject->readDevInfCallback) { + smlTrace(TRACE_INTERNAL, "%s: calling read DevInf callback", __func__); SmlDevInf *devinf = dsObject->readDevInfCallback( dsObject, smlLocationGetURI(smlSessionGetTarget(dsObject->session)), @@ -602,7 +607,13 @@ if (devinf) { smlDevInfAgentSetDevInf(dsObject->agent, devinf); dsObject->remoteDevInf = smlDevInfAgentGetDevInf(dsObject->agent); + /* smlDevInfAgentSetDevInf consumes the DevInf object. + * So the reference counter must be incremented for + * remoteDevInf. + */ + smlDevInfRef(dsObject->remoteDevInf); _update_session_config_from_devinf(dsObject); + smlTrace(TRACE_EXIT, "%s - cached DevInf", __func__); return TRUE; } } @@ -615,9 +626,11 @@ dsObject->agent, dsObject->session, error); + smlTrace(TRACE_EXIT, "%s - no remote DevInf available at all", __func__); return FALSE; } error: + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); return FALSE; } @@ -708,6 +721,7 @@ if (dsObject->writeDevInfCallback) { /* store device info */ + smlTrace(TRACE_INTERNAL, "%s: calling write DevInf callback", __func__); if (!dsObject->writeDevInfCallback( dsObject, dsObject->localDevInf, dsObject->writeDevInfUserdata, error)) Modified: trunk/libsyncml/data_sync_api/standard.h ============================================================================== --- trunk/libsyncml/data_sync_api/standard.h Tue Mar 10 14:35:23 2009 (r969) +++ trunk/libsyncml/data_sync_api/standard.h Fri Mar 13 10:29:53 2009 (r970) @@ -91,7 +91,6 @@ const char *localID, SmlError **error); - /** * Returns the identity of the remote sync peer. This is the * <Source></Source> tag. The returned reference is not owned Modified: trunk/libsyncml/sml_transport.c ============================================================================== --- trunk/libsyncml/sml_transport.c Tue Mar 10 14:35:23 2009 (r969) +++ trunk/libsyncml/sml_transport.c Fri Mar 13 10:29:53 2009 (r970) @@ -1065,7 +1065,7 @@ if (tsp->connected && !smlTransportIsServer(tsp)) { smlErrorSet(error, SML_ERROR_GENERIC, - "If the transport is connected then it cannot be finalized."); + "If a client transport is connected then it cannot be finalized."); goto error; } |