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.

103 lines
4.7 KiB

  1. From 7fb5b6a19b06dc5b0a7f32261551b206b1e6a563 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Sun, 8 Jan 2017 19:24:26 +0100
  4. Subject: [PATCH 3/3] src: move OCClientResponse from stack to heap
  5. OCClientResponse is about 50KByte and should not be stored on the
  6. stack. On LEDE with MIPS, musl libc this causes a segmentation fault.
  7. Moving this structure to the heap is the simple solution for this
  8. problem, but this structure should be shrinked.
  9. Change-Id: I7887f93450f45b8031fcdfffb9ee2214fc3d5dd2
  10. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  11. ---
  12. resource/src/InProcServerWrapper.cpp | 44 +++++++++++++++++++++---------------
  13. 1 file changed, 26 insertions(+), 18 deletions(-)
  14. --- a/resource/src/InProcServerWrapper.cpp
  15. +++ b/resource/src/InProcServerWrapper.cpp
  16. @@ -568,51 +568,58 @@ namespace OC
  17. }
  18. else
  19. {
  20. - OCEntityHandlerResponse response;
  21. + OCEntityHandlerResponse *response = NULL;
  22. +
  23. + response = (OCEntityHandlerResponse *)OICCalloc(1, sizeof(*response));
  24. + if (!response) {
  25. + result = OC_STACK_MALFORMED_RESPONSE;
  26. + throw OCException(OC::Exception::STR_NULL_RESPONSE, OC_STACK_MALFORMED_RESPONSE);
  27. + }
  28. +
  29. // OCRepPayload* payLoad = pResponse->getPayload();
  30. HeaderOptions serverHeaderOptions = pResponse->getHeaderOptions();
  31. - response.requestHandle = pResponse->getRequestHandle();
  32. - response.resourceHandle = pResponse->getResourceHandle();
  33. - response.ehResult = pResponse->getResponseResult();
  34. + response->requestHandle = pResponse->getRequestHandle();
  35. + response->resourceHandle = pResponse->getResourceHandle();
  36. + response->ehResult = pResponse->getResponseResult();
  37. - response.payload = reinterpret_cast<OCPayload*>(pResponse->getPayload());
  38. + response->payload = reinterpret_cast<OCPayload*>(pResponse->getPayload());
  39. - response.persistentBufferFlag = 0;
  40. + response->persistentBufferFlag = 0;
  41. - response.numSendVendorSpecificHeaderOptions = serverHeaderOptions.size();
  42. + response->numSendVendorSpecificHeaderOptions = serverHeaderOptions.size();
  43. int i = 0;
  44. for (auto it=serverHeaderOptions.begin(); it != serverHeaderOptions.end(); ++it)
  45. {
  46. - response.sendVendorSpecificHeaderOptions[i].protocolID = OC_COAP_ID;
  47. - response.sendVendorSpecificHeaderOptions[i].optionID =
  48. + response->sendVendorSpecificHeaderOptions[i].protocolID = OC_COAP_ID;
  49. + response->sendVendorSpecificHeaderOptions[i].optionID =
  50. static_cast<uint16_t>(it->getOptionID());
  51. - response.sendVendorSpecificHeaderOptions[i].optionLength =
  52. + response->sendVendorSpecificHeaderOptions[i].optionLength =
  53. (it->getOptionData()).length() + 1;
  54. std::string optionData = it->getOptionData();
  55. std::copy(optionData.begin(),
  56. optionData.end(),
  57. - response.sendVendorSpecificHeaderOptions[i].optionData);
  58. - response.sendVendorSpecificHeaderOptions[i].optionData[it->getOptionData().length()]
  59. + response->sendVendorSpecificHeaderOptions[i].optionData);
  60. + response->sendVendorSpecificHeaderOptions[i].optionData[it->getOptionData().length()]
  61. = '\0';
  62. i++;
  63. }
  64. - if(OC_EH_RESOURCE_CREATED == response.ehResult)
  65. + if(OC_EH_RESOURCE_CREATED == response->ehResult)
  66. {
  67. - pResponse->getNewResourceUri().copy(response.resourceUri,
  68. - sizeof (response.resourceUri) - 1);
  69. - response.resourceUri[pResponse->getNewResourceUri().length()] = '\0';
  70. + pResponse->getNewResourceUri().copy(response->resourceUri,
  71. + sizeof (response->resourceUri) - 1);
  72. + response->resourceUri[pResponse->getNewResourceUri().length()] = '\0';
  73. }
  74. if(cLock)
  75. {
  76. std::lock_guard<std::recursive_mutex> lock(*cLock);
  77. - result = OCDoResponse(&response);
  78. + result = OCDoResponse(response);
  79. }
  80. else
  81. {
  82. - OICFree(response.payload);
  83. + OICFree(response->payload);
  84. result = OC_STACK_ERROR;
  85. }
  86. @@ -620,6 +627,7 @@ namespace OC
  87. {
  88. oclog() << "Error sending response\n";
  89. }
  90. + OICFree(response);
  91. return result;
  92. }
  93. }