You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.1 KiB

  1. From d8cf30cb0abd5fa8f6282b490618204d683b625c Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Mon, 3 Oct 2016 21:00:28 +0200
  4. Subject: [PATCH 1/3] csdk: move OCEntityHandlerResponse from stack to heap
  5. OCEntityHandlerResponse is over 50KByte and I got a stack overflow on MIPS
  6. running on LEDE without this patch. Instead of storing
  7. OCEntityHandlerResponse on the program stack, allocate some memory on
  8. the heap and free it afterwards again.
  9. This fixes one part of this issue for me:
  10. https://jira.iotivity.org/browse/IOT-1374
  11. Change-Id: I365a5c7a34dce2dfb0897a20b57a13ba566748ec
  12. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  13. ---
  14. resource/csdk/stack/src/ocresource.c | 24 +++++++++++++++++-------
  15. 1 file changed, 17 insertions(+), 7 deletions(-)
  16. --- a/resource/csdk/stack/src/ocresource.c
  17. +++ b/resource/csdk/stack/src/ocresource.c
  18. @@ -774,15 +774,25 @@ static bool includeThisResourceInRespons
  19. OCStackResult SendNonPersistantDiscoveryResponse(OCServerRequest *request, OCResource *resource,
  20. OCPayload *discoveryPayload, OCEntityHandlerResult ehResult)
  21. {
  22. - OCEntityHandlerResponse response = {0};
  23. + OCEntityHandlerResponse *response = NULL;
  24. + OCStackResult result = OC_STACK_ERROR;
  25. - response.ehResult = ehResult;
  26. - response.payload = discoveryPayload;
  27. - response.persistentBufferFlag = 0;
  28. - response.requestHandle = (OCRequestHandle) request->requestId;
  29. - response.resourceHandle = (OCResourceHandle) resource;
  30. + response = (OCEntityHandlerResponse *)OICCalloc(1, sizeof(*response));
  31. + VERIFY_PARAM_NON_NULL(TAG, response, "Failed allocating OCEntityHandlerResponse");
  32. - return OCDoResponse(&response);
  33. + response->ehResult = ehResult;
  34. + response->payload = discoveryPayload;
  35. + response->persistentBufferFlag = 0;
  36. + response->requestHandle = (OCRequestHandle) request->requestId;
  37. + response->resourceHandle = (OCResourceHandle) resource;
  38. +
  39. + result = OCDoResponse(response);
  40. +
  41. + OICFree(response);
  42. + return result;
  43. +
  44. +exit:
  45. + return OC_STACK_NO_MEMORY;
  46. }
  47. static OCStackResult EHRequest(OCEntityHandlerRequest *ehRequest, OCPayloadType type,