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

Cleanup and fix some memory leaks #43

Merged
merged 6 commits into from
Nov 11, 2023
Merged

Conversation

szhorvat
Copy link
Contributor

@szhorvat szhorvat commented Nov 11, 2023

This carries over all changes that were made in igraph, not just igraph/igraph#2433 There's a fix for void parameter lists.

Some of the headers I removed on the igraph side were actually necessary here (for rand()).

I tested that this compiled with -std=gnu89 and -std=c99, but it does not compile with -std=c89. That's because plfit uses many functions which were present as a GNU extension for a long time, but only became standard in C99.

@szhorvat
Copy link
Contributor Author

@ntamas It might be a good idea to check the Clang Analyzer results on this package. Do it like this:

cmake .. -GXcode
open plfit.xcodeproj

The use Product -> Analyze.

There are "Left operand of > is a garbage value" warnings in plfit.c, which I think come from omitting the error check from the plfit_estimate_alpha_continuous() and plfit_continuous() calls. But we can't do the error check when OpenMP is enabled, right?

Then there are some null pointer dereference warnings in lbfgs.c, but I'm not sure they are correct ...

Copy link
Owner

@ntamas ntamas left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@ntamas ntamas merged commit ae34bcd into ntamas:main Nov 11, 2023
3 checks passed
@ntamas
Copy link
Owner

ntamas commented Nov 11, 2023

I'll do the static analysis and then check whether I can fix any more of those warnings.

Error checks with OpenMP are indeed problematic -- you cannot bail out in the middle of an OpenMP section but you need to coordinate until you get back to the main thread and then you can do the cleanup there. I'll look into this.

@ntamas
Copy link
Owner

ntamas commented Nov 11, 2023

Okay, FYI, I went through the static analysis results.

  • Most of the warnings are harmless, clang does not seem to be happy with leaving certain output arguments as-is in case of an error, but I think this is the right thing to do.
  • I'd rather not touch lbfgs.c as it is vendored code and I don't know the internals so I can't decide what's a genuine error and what's not without investing lots of extra time in it.
  • As you said, the reason for the warnings in plfit.c is the lack of PLFIT_CHECK() calls. I can probably work around this by having a shared plfit_error_t shared_error variable declared outside the loop and a per-thread plfit_error_t error that updates shared_error if needed. If I manage to fix this, I'll add a commit to master.

@szhorvat
Copy link
Contributor Author

  • As you said, the reason for the warnings in plfit.c is the lack of PLFIT_CHECK() calls. I can probably work around this by having a shared plfit_error_t shared_error variable declared outside the loop and a per-thread plfit_error_t error that updates shared_error if needed. If I manage to fix this, I'll add a commit to master.

I wouldn't spend much time on this right now, as the errors are probably OOM only, and if that happens, the program is likely to crash anyway.

At one point we'll need to figure out a proper way to do error checks from within OpenMP code and start adding OpenMP to igraph itself. That will require careful thought and it's likely to be a lot of work.

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.

2 participants