Merge lp:~zorba-coders/zorba/xqxq-memory-smash into lp:zorba/xqxq-module

Proposed by Chris Hillery
Status: Merged
Approved by: Juan Zacarias
Approved revision: 42
Merged at revision: 41
Proposed branch: lp:~zorba-coders/zorba/xqxq-memory-smash
Merge into: lp:zorba/xqxq-module
Diff against target: 313 lines (+130/-43)
7 files modified
src/xqxq.xq.src/xqxq.cpp (+52/-24)
src/xqxq.xq.src/xqxq.h (+23/-19)
test/ExpQueryResults/xqxq/url-schema-resolver3.xml.res (+2/-0)
test/Queries/xqxq/error-in-query.spec (+2/-0)
test/Queries/xqxq/error-in-query.xq (+21/-0)
test/Queries/xqxq/test.xml (+1/-0)
test/Queries/xqxq/url-schema-resolver3.xq (+29/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/xqxq-memory-smash
Reviewer Review Type Date Requested Status
Juan Zacarias Approve
Chris Hillery Approve
Review via email: mp+130657@code.launchpad.net

Commit message

Fix several memory errors having to do with freeing URIMappers / URLResolvers.

To post a comment you must log in.
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job xqxq-memory-smash-2012-10-20T02-21-41.631Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Juan Zacarias (juan457) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job xqxq-memory-smash-2012-10-22T16-48-40.826Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/xqxq.xq.src/xqxq.cpp'
--- src/xqxq.xq.src/xqxq.cpp 2012-10-19 01:22:47 +0000
+++ src/xqxq.xq.src/xqxq.cpp 2012-10-20 02:20:24 +0000
@@ -179,20 +179,39 @@
179 String errDescription(aErrorMessage);179 String errDescription(aErrorMessage);
180 throw USER_EXCEPTION(errQName, errDescription);180 throw USER_EXCEPTION(errQName, errDescription);
181 }181 }
182 182
183 /*******************************************************************************************183 /*******************************************************************************************
184 *******************************************************************************************/184 *******************************************************************************************/
185 185
186 QueryData::QueryData(XQuery_t aQuery, URIMapper *aMapper, URLResolver *aResolver)
187 : theQuery(aQuery),
188 theURIMapper(aMapper),
189 theURLResolver(aResolver)
190 {
191 }
192
193 QueryData::~QueryData()
194 {
195 theQuery->close();
196 delete theURIMapper;
197 delete theURLResolver;
198 }
199
200 /*******************************************************************************************
201 *******************************************************************************************/
202
186 QueryMap::QueryMap()203 QueryMap::QueryMap()
187 {204 {
188 QueryMap::queryMap = new QueryMap_t();205 QueryMap::queryMap = new QueryMap_t();
189 }206 }
190207
191 bool 208 bool
192 QueryMap::storeQuery(const String& aKeyName, XQuery_t aQuery)209 QueryMap::storeQuery(const String& aKeyName, XQuery_t aQuery,
210 URIMapper* aMapper, URLResolver* aResolver)
193 {211 {
212 QueryData_t lQueryData(new QueryData(aQuery, aMapper, aResolver));
194 std::pair<QueryMap_t::iterator,bool> ret;213 std::pair<QueryMap_t::iterator,bool> ret;
195 ret = queryMap->insert(std::pair<String, XQuery_t>(aKeyName, aQuery));214 ret = queryMap->insert(std::pair<String, QueryData_t>(aKeyName, lQueryData));
196 return ret.second;215 return ret.second;
197 }216 }
198217
@@ -204,7 +223,7 @@
204 if(lIter == queryMap->end())223 if(lIter == queryMap->end())
205 return NULL;224 return NULL;
206 225
207 XQuery_t lQuery = lIter->second;226 XQuery_t lQuery = lIter->second->getQuery();
208227
209 return lQuery;228 return lQuery;
210 }229 }
@@ -216,14 +235,27 @@
216235
217 if(lIter == queryMap->end())236 if(lIter == queryMap->end())
218 return false;237 return false;
219
220 lIter->second->close();
221238
222 queryMap->erase(lIter);239 queryMap->erase(lIter);
223
224 return true;240 return true;
225 }241 }
226242
243 void
244 QueryMap::destroy() throw()
245 {
246 if(queryMap)
247 {
248 for (QueryMap_t::const_iterator lIter = queryMap->begin();
249 lIter != queryMap->end(); ++lIter)
250 {
251 deleteQuery(lIter->first);
252 }
253 queryMap->clear();
254 delete queryMap;
255 }
256 delete this;
257 }
258
227 /*******************************************************************************************259 /*******************************************************************************************
228 *******************************************************************************************/260 *******************************************************************************************/
229 static void streamReleaser(std::istream* aStream)261 static void streamReleaser(std::istream* aStream)
@@ -344,7 +376,6 @@
344 {376 {
345 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);377 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
346 StaticContext_t lSctxChild = aSctx->createChildContext();378 StaticContext_t lSctxChild = aSctx->createChildContext();
347 StaticContext_t lMapperSctx = aSctx->createChildContext();
348 379
349 QueryMap* lQueryMap;380 QueryMap* lQueryMap;
350 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))381 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
@@ -360,16 +391,16 @@
360 XQuery_t lQuery;391 XQuery_t lQuery;
361 392
362 StaticContext_t ltempSctx = lZorba->createStaticContext();393 StaticContext_t ltempSctx = lZorba->createStaticContext();
363 XQXQURLResolver* lResolver = NULL;394 std::auto_ptr<XQXQURLResolver> lResolver;
364 XQXQURIMapper* lMapper = NULL;395 std::auto_ptr<XQXQURIMapper> lMapper;
365396
366 if ( aArgs.size() > 2 )397 if ( aArgs.size() > 2 )
367 {398 {
368 Item lMapperFunctionItem = getItemArgument(aArgs, 2);399 Item lMapperFunctionItem = getItemArgument(aArgs, 2);
369 if (!lMapperFunctionItem.isNull())400 if (!lMapperFunctionItem.isNull())
370 {401 {
371 lMapper = new XQXQURIMapper(lMapperFunctionItem, lSctxChild);402 lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
372 ltempSctx->registerURIMapper(lMapper);403 ltempSctx->registerURIMapper(lMapper.get());
373 }404 }
374 }405 }
375406
@@ -378,8 +409,8 @@
378 Item lResolverFunctionItem = getItemArgument(aArgs, 1);409 Item lResolverFunctionItem = getItemArgument(aArgs, 1);
379 if (!lResolverFunctionItem.isNull())410 if (!lResolverFunctionItem.isNull())
380 {411 {
381 lResolver = new XQXQURLResolver(lResolverFunctionItem, lSctxChild);412 lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
382 ltempSctx->registerURLResolver(lResolver);413 ltempSctx->registerURLResolver(lResolver.get());
383 }414 }
384415
385 }416 }
@@ -390,6 +421,7 @@
390 }421 }
391 catch (XQueryException& xe)422 catch (XQueryException& xe)
392 {423 {
424 lQuery = NULL;
393 std::ostringstream err;425 std::ostringstream err;
394 err << "The query compiled using xqxq:prepare-main-module raised an error at"426 err << "The query compiled using xqxq:prepare-main-module raised an error at"
395 << " line " << xe.source_line() << " column " << xe.source_column() << ": " << xe.what();427 << " line " << xe.source_line() << " column " << xe.source_column() << ": " << xe.what();
@@ -399,6 +431,7 @@
399 }431 }
400 catch (ZorbaException& e)432 catch (ZorbaException& e)
401 {433 {
434 lQuery = NULL;
402 std::ostringstream err;435 std::ostringstream err;
403 err << "The query compiled using xqxq:prepare-main-module raised an error: "436 err << "The query compiled using xqxq:prepare-main-module raised an error: "
404 << e.what();437 << e.what();
@@ -406,7 +439,7 @@
406 e.diagnostic().qname().ns(), e.diagnostic().qname().localname());439 e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
407 throw USER_EXCEPTION(errQName, err.str());440 throw USER_EXCEPTION(errQName, err.str());
408 }441 }
409 442
410 uuid lUUID;443 uuid lUUID;
411 uuid::create(&lUUID);444 uuid::create(&lUUID);
412 445
@@ -415,13 +448,8 @@
415448
416 String lStrUUID = lStream.str();449 String lStrUUID = lStream.str();
417450
418 lQueryMap->storeQuery(lStrUUID, lQuery);451 lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
419 452
420 if (lResolver)
421 delete lResolver;
422 if (lMapper)
423 delete lMapper;
424
425 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));453 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
426 }454 }
427455
428456
=== modified file 'src/xqxq.xq.src/xqxq.h'
--- src/xqxq.xq.src/xqxq.h 2012-10-18 00:34:20 +0000
+++ src/xqxq.xq.src/xqxq.h 2012-10-20 02:20:24 +0000
@@ -49,35 +49,39 @@
4949
50 };50 };
5151
5252 /**
53 class QueryMap : public ExternalFunctionParameter{53 * @brief Bag class for objects associated with a prepared query
54 private:54 */
55 typedef std::map<String, XQuery_t> QueryMap_t;55 class QueryData : public SmartObject
56 {
57 private:
58 XQuery_t theQuery;
59 URIMapper* theURIMapper;
60 URLResolver* theURLResolver;
61
62 public:
63 QueryData(XQuery_t aQuery, URIMapper* aMapper, URLResolver* aResolver);
64 virtual ~QueryData();
65 XQuery_t getQuery() { return theQuery; }
66 };
67 typedef SmartPtr<QueryData> QueryData_t;
68
69 class QueryMap : public ExternalFunctionParameter
70 {
71 private:
72 typedef std::map<String, QueryData_t> QueryMap_t;
56 QueryMap_t* queryMap;73 QueryMap_t* queryMap;
5774
58 public:75 public:
59 QueryMap();76 QueryMap();
60 bool 77 bool
61 storeQuery(const String&, XQuery_t);78 storeQuery(const String&, XQuery_t, URIMapper*, URLResolver*);
62 XQuery_t79 XQuery_t
63 getQuery(const String&);80 getQuery(const String&);
64 bool 81 bool
65 deleteQuery(const String&);82 deleteQuery(const String&);
66 virtual void 83 virtual void
67 destroy() throw()84 destroy() throw();
68 {
69 if(queryMap)
70 {
71 for (QueryMap_t::const_iterator lIter = queryMap->begin();
72 lIter != queryMap->end(); ++lIter)
73 {
74 lIter->second->close();
75 }
76 queryMap->clear();
77 delete queryMap;
78 }
79 delete this;
80 };
81 };85 };
8286
83 class XQXQFunction : public ContextualExternalFunction87 class XQXQFunction : public ContextualExternalFunction
8488
=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver3.xml.res'
--- test/ExpQueryResults/xqxq/url-schema-resolver3.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-schema-resolver3.xml.res 2012-10-20 02:20:24 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
03
=== added file 'test/Queries/xqxq/error-in-query.spec'
--- test/Queries/xqxq/error-in-query.spec 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/error-in-query.spec 2012-10-20 02:20:24 +0000
@@ -0,0 +1,2 @@
1Error: http://www.w3.org/2005/xqt-errors:XQST0033
2
03
=== added file 'test/Queries/xqxq/error-in-query.xq'
--- test/Queries/xqxq/error-in-query.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/error-in-query.xq 2012-10-20 02:20:24 +0000
@@ -0,0 +1,21 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace op = 'http://www.zorba-xquery.com/options/features';
4declare namespace f = 'http://www.zorba-xquery.com/features';
5declare option op:enable 'f:hof';
6
7declare function local:url-resolver($namespace as xs:string, $entity as xs:string) {
8switch($entity)
9case 'schema'
10 return switch($namespace)
11 case 'http://www.w3.org/XQueryTest' return doc('/tmp/atomic.xsd')
12 default return ()
13default return ()
14};
15
16variable $queryID := xqxq:prepare-main-module(
17 "declare namespace foo='http://test';
18 declare namespace foo='http://test';
19 1",
20 local:url-resolver#2, ());
21xqxq:evaluate($queryID)
022
=== added file 'test/Queries/xqxq/test.xml'
--- test/Queries/xqxq/test.xml 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/test.xml 2012-10-20 02:20:24 +0000
@@ -0,0 +1,1 @@
1<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/Queries/xqxq/url-schema-resolver3.xq'
--- test/Queries/xqxq/url-schema-resolver3.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-schema-resolver3.xq 2012-10-20 02:20:24 +0000
@@ -0,0 +1,29 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4
5declare namespace op = "http://www.zorba-xquery.com/options/features";
6declare namespace f = "http://www.zorba-xquery.com/features";
7declare option op:enable "f:hof";
8
9declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
10 if($namespace = 'http://test' and $entity = 'schema')
11 then
12 doc('test.xsd')
13 else
14 ()
15};
16
17variable $contextQueryID := xqxq:prepare-main-module(
18 "import schema namespace test = 'http://test';
19 declare variable $cwd as xs:anyURI external;
20 validate { doc(resolve-uri('test.xml', $cwd)) }",
21 resolver:url-resolver#2, ());
22xqxq:bind-variable($contextQueryID, fn:QName("", "cwd"), resolve-uri("."));
23variable $contextItem := xqxq:evaluate($contextQueryID);
24
25variable $queryID := xqxq:prepare-main-module(
26 "import schema namespace test = 'http://test'; //*:test",
27 resolver:url-resolver#2, ());
28xqxq:bind-context-item($queryID, $contextItem);
29xqxq:evaluate($queryID)

Subscribers

People subscribed via source and target branches

to all changes: