summaryrefslogtreecommitdiffstats
path: root/src/usbmux.c
diff options
context:
space:
mode:
authorGravatar Zach C2008-08-06 21:04:09 -0700
committerGravatar Matt Colyer2008-08-06 21:04:09 -0700
commitbef655966045af34e1f20a7211f0cab2e7e79001 (patch)
tree590b41891fab48af0c3f35431f7476bbc2b4b0a2 /src/usbmux.c
parentd81a3c5c412cca9b8327d6d27625bc52650e9651 (diff)
downloadlibplist-bef655966045af34e1f20a7211f0cab2e7e79001.tar.gz
libplist-bef655966045af34e1f20a7211f0cab2e7e79001.tar.bz2
Adds locking and fixes a minor bug in mux_recv
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/usbmux.c')
-rw-r--r--src/usbmux.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/usbmux.c b/src/usbmux.c
index 235a1f2..d79ee47 100644
--- a/src/usbmux.c
+++ b/src/usbmux.c
@@ -301,8 +301,15 @@ int mux_recv(usbmux_connection *connection, char *data, uint32 datalen) {
for (i = 0; i < connections; i++) {
if (connlist[i]->header->sport == header->dport && connlist[i]->header->dport == header->sport) {
// we have a winner.
+ char *nfb = (char*)malloc(sizeof(char) * (connlist[i]->r_len + (bytes - 28)));
+ if (connlist[i]->recv_buffer && connlist[i]->r_len) {
+ memcpy(nfb, connlist[i]->recv_buffer, connlist[i]->r_len);
+ free(connlist[i]->recv_buffer);
+ }
connlist[i]->r_len += bytes - 28;
- connlist[i]->recv_buffer = (char*)realloc(connlist[i]->recv_buffer, sizeof(char) * connection->r_len); // grow their buffer
+ //connlist[i]->recv_buffer = (char*)realloc(connlist[i]->recv_buffer, sizeof(char) * connection->r_len); // grow their buffer
+ connlist[i]->recv_buffer = nfb;
+ nfb = NULL; // A cookie for you if you can guess what "nfb" means.
complex = connlist[i]->r_len - (bytes - 28);
memcpy(connlist[i]->recv_buffer+complex, buffer+28, bytes-28); // paste into their buffer
connlist[i]->header->ocnt += bytes-28;