hicz Posted December 10, 2018 Share Posted December 10, 2018 I was working on some custom json nodes. I wanted to export some data using json format, so I did that like as follow in cookMySop: UT_JSONValueMap *rootMap = new UT_JSONValueMap; UT_JSONValue *floatV = new UT_JSONValue(35.0); rootMap->append("Value1", floatV); rootValue->setMap(rootMap);//rootValue is an object of UT_JSONValue rootValue->saveToFile("G:\\test.json"); after that, I wanted to remove temp exporting data: rootValue->setNull(); delete rootMap; rootMap = nullptr; delete floatV; floatV = nullptr; however, using "delete" caused an error. without "delete" everything works fine, but I am afraid there can be some memory leakage. is there something wrong? Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted December 10, 2018 Share Posted December 10, 2018 Without looking into that classes, I would assume that UT_JSONValueMap->append() takes ownership of its contents and deleting rootMap also deletes the floatV data, and so you're getting a "double free" error. See if UT_JSONValueMap owns the values and if so, you don't need to delete floatV yourself. 1 Quote Link to comment Share on other sites More sharing options...
hicz Posted December 10, 2018 Author Share Posted December 10, 2018 41 minutes ago, Stalkerx777 said: Without looking into that classes, I would assume that UT_JSONValueMap->append() takes ownership of its contents and deleting rootMap also deletes the floatV data, and so you're getting a "double free" error. See if UT_JSONValueMap owns the values and if so, you don't need to delete floatV yourself. Thank you, tested that, deleting outer object and all its members were gone with it. There is no need to delete member objects manually. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.