Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Potentially invalid allocation in the server example #128

Closed
Kerollmops opened this issue Apr 17, 2020 · 1 comment · Fixed by #129
Closed

Potentially invalid allocation in the server example #128

Kerollmops opened this issue Apr 17, 2020 · 1 comment · Fixed by #129

Comments

@Kerollmops
Copy link

In this snippet we can see that the allocation size is defined to be the size of what is under the dereferencing of fsm which means that it will be sizeof(struct raft_fsm).

The problem is that it is not the size of the struct we want to use, the correct size should be sizeof(Fsm), I am missing something?

raft/example/server.c

Lines 70 to 83 in 4d3de31

static int FsmInit(struct raft_fsm *fsm)
{
struct Fsm *f = raft_malloc(sizeof *fsm);
if (f == NULL) {
return RAFT_NOMEM;
}
f->count = 0;
fsm->version = 1;
fsm->data = f;
fsm->apply = FsmApply;
fsm->snapshot = FsmSnapshot;
fsm->restore = FsmRestore;
return 0;
}

@freeekanayaka
Copy link
Contributor

freeekanayaka commented Apr 17, 2020

You're right. I've submitted PR #129 to fix this. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants