Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct json_rpc_buffer initialization order #473

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

tdb3
Copy link
Contributor

@tdb3 tdb3 commented Nov 11, 2024

While reviewing #471, noticed that json_rpc_buffer initialization tries to memset before checking if the malloc was successful.

This moves the memset after the check.

Did a basic test by building and running on a Supra 401. Started mining on testnet4 on a ckpool instance. Jobs were received and shares were accepted.

Note: The malloc failure is unlikely to occur, so we're not seeing an issue now, but if it does occur (e.g. other future code changes chew up too much heap), then we could actually see the error in the log.

Performs memset after checking if the malloc was successful.
Safer, avoids segfault on (unlikely) unsuccessful malloc,
and allows the error printing to occur.
if (json_rpc_buffer == NULL) {
printf("Error: Failed to allocate memory for buffer\n");
exit(1);
}
memset(json_rpc_buffer, 0, BUFFER_SIZE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for future proofing.

@skot skot merged commit e39b6db into skot:master Nov 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants