As part of my .NET interop work, I hit an interesting issue in OCDoResource
(ocstack.c):
The method takes a ?payload? parameter, and then at the end of the method, it
cleans up and deletes that payload:
OCStackResult OCDoResource(OCDoHandle *handle,
OCMethod method,
const char *requestUri,
const OCDevAddr *destination,
OCPayload* payload,
OCConnectivityType connectivityType,
OCQualityOfService qos,
OCCallbackData *cbData,
OCHeaderOption *options,
uint8_t numOptions)
{
[?]
// This is the owner of the payload object, so we free it
OCPayloadDestroy(payload);
[?]
}
The code is clearly stating it owns the payload and thus should free it.
However I don?t see how it owns it, if it?s a parameter you?re passing in?
I hit this because I was making sure I cleaned up my resources, but hit a crash
because OCDoResource already destroyed the payload earlier. It?s actually
rather tricky to work around, because I rely on the Garbage Collector to call
the finalizer to destroy stuff, but if the payload happens to have been used in
this method, I?ll hit a crash, but if I don?t clean up in the finalizer, I?d be
leaking memory.
Thanks
/Morten
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.iotivity.org/pipermail/iotivity-dev/attachments/20161208/d7fe613c/attachment.html>