Skip to content

Commit

Permalink
Fix heap corruption due to wrong usage of malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
wirg_mo committed Oct 11, 2021
1 parent 5a2e425 commit 66c4f97
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 81 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 1.0.0-dev.4

### Fix heap corruption due to wrong usage of `malloc.allocate`
- Use periodic timer to poll sockets every second
- Poll all messages on socket instead of one for each event to not loose messages
- Reuse zeromq message pointer
- Improve return code handling
- Rename `_isActive` of `ZContext` to `_shutdown`
- Rename `_handle` and `_zmq` of `ZSocket` to `_socket` and `_context`
- Add stream for `ZFrames` to `ZSocket`
- Always show error code in `ZeroMQException`
- Fix pubspec of example


## 1.0.0-dev.3

### Add example, subscriptions for `sub` sockets and code cleanup
Expand Down
12 changes: 6 additions & 6 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.1.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -56,7 +56,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0-dev.3"
version: "1.0.0-dev.4"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -101,7 +101,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.10"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -162,7 +162,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand All @@ -178,5 +178,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.15.0-116.0.dev <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.17.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.15.0-116.0.dev <3.0.0"
sdk: '>=2.14.0 <3.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
19 changes: 19 additions & 0 deletions lib/src/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ typedef zmq_poller_remove_native = Int32 Function(
typedef zmq_poller_remove_dart = int Function(
ZMQPoller poller, ZMQSocket socket);

typedef zmq_poll_native = Int32 Function(
Pointer<ZMQPollItem> items, Int32 nitems, Int64 timeout);
typedef zmq_poll_dart = int Function(
Pointer<ZMQPollItem> items, int nitems, int timeout);

typedef zmq_poller_wait_all_native = Int32 Function(ZMQPoller poller,
Pointer<ZMQPollerEvent> events, Int32 count, Int64 timeout);
typedef zmq_poller_wait_all_dart = int Function(
Expand Down Expand Up @@ -109,6 +114,17 @@ class ZMQPollerEvent extends Struct {
external int events;
}

class ZMQPollItem extends Struct {
external ZMQSocket socket;
@Int32()
external int fd;

@Int16()
external int events;
@Int16()
external int revents;
}

class ZMQBindings {
final DynamicLibrary library;

Expand All @@ -127,6 +143,7 @@ class ZMQBindings {
late final zmq_poller_destroy_dart zmq_poller_destroy;
late final zmq_poller_add_dart zmq_poller_add;
late final zmq_poller_remove_dart zmq_poller_remove;
late final zmq_poll_dart zmq_poll;
late final zmq_poller_wait_all_dart zmq_poller_wait_all;

late final zmq_msg_init_dart zmq_msg_init;
Expand Down Expand Up @@ -167,6 +184,8 @@ class ZMQBindings {
'zmq_poller_add');
zmq_poller_remove = library.lookupFunction<zmq_poller_remove_native,
zmq_poller_remove_dart>('zmq_poller_remove');
zmq_poll =
library.lookupFunction<zmq_poll_native, zmq_poll_dart>('zmq_poll');
zmq_poller_wait_all = library.lookupFunction<zmq_poller_wait_all_native,
zmq_poller_wait_all_dart>('zmq_poller_wait_all');

Expand Down
2 changes: 2 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ const int ENOTCONN = _errorBase + 15;
const int ETIMEDOUT = _errorBase + 16;
const int EHOSTUNREACH = _errorBase + 17;
const int ENETRESET = _errorBase + 18;

const int EAGAIN = 11;
Loading

0 comments on commit 66c4f97

Please sign in to comment.