Bug 1098583 - Clean up data channel open request. r=jesup, a=lsblakk
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Wed, 26 Nov 2014 14:00:36 -0500
changeset 234114 2d431a82b30da90ee2c48e74c7fc271f433e5f0d
parent 234113 d21e91a547d8b5e2254046ea25a095216af2b354
child 234115 8aafebccd2abe82b7d1d78af05d7faf5c5989dd9
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersjesup, lsblakk
bugs1098583
milestone35.0
Bug 1098583 - Clean up data channel open request. r=jesup, a=lsblakk
netwerk/sctp/datachannel/DataChannel.cpp
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -980,23 +980,25 @@ DataChannelConnection::SendOpenAckMessag
 }
 
 int32_t
 DataChannelConnection::SendOpenRequestMessage(const nsACString& label,
                                               const nsACString& protocol,
                                               uint16_t stream, bool unordered,
                                               uint16_t prPolicy, uint32_t prValue)
 {
-  int label_len = label.Length(); // not including nul
-  int proto_len = protocol.Length(); // not including nul
+  const int label_len = label.Length(); // not including nul
+  const int proto_len = protocol.Length(); // not including nul
+  // careful - request struct include one char for the label
+  const int req_size = sizeof(struct rtcweb_datachannel_open_request) - 1 +
+                        label_len + proto_len;
   struct rtcweb_datachannel_open_request *req =
-    (struct rtcweb_datachannel_open_request*) moz_xmalloc((sizeof(*req)-1) + label_len + proto_len);
-   // careful - request includes 1 char label
+    (struct rtcweb_datachannel_open_request*) moz_xmalloc(req_size);
 
-  memset(req, 0, sizeof(struct rtcweb_datachannel_open_request));
+  memset(req, 0, req_size);
   req->msg_type = DATA_CHANNEL_OPEN_REQUEST;
   switch (prPolicy) {
   case SCTP_PR_SCTP_NONE:
     req->channel_type = DATA_CHANNEL_RELIABLE;
     break;
   case SCTP_PR_SCTP_TTL:
     req->channel_type = DATA_CHANNEL_PARTIAL_RELIABLE_TIMED;
     break;
@@ -1015,18 +1017,17 @@ DataChannelConnection::SendOpenRequestMe
 
   req->reliability_param = htonl(prValue);
   req->priority = htons(0); /* XXX: add support */
   req->label_length = htons(label_len);
   req->protocol_length = htons(proto_len);
   memcpy(&req->label[0], PromiseFlatCString(label).get(), label_len);
   memcpy(&req->label[label_len], PromiseFlatCString(protocol).get(), proto_len);
 
-  // sizeof(*req) already includes +1 byte for label, need nul for both strings
-  int32_t result = SendControlMessage(req, (sizeof(*req)-1) + label_len + proto_len, stream);
+  int32_t result = SendControlMessage(req, req_size, stream);
 
   moz_free(req);
   return result;
 }
 
 // XXX This should use a separate thread (outbound queue) which should
 // select() to know when to *try* to send data to the socket again.
 // Alternatively, it can use a timeout, but that's guaranteed to be wrong