Page MenuHome

Memory allocation confusion
Closed, InvalidPublic


I ran static analysis on some parts of Blender and found some confusing memory allocation warnings in our code.
Just as an example:

blf_font.c Line 491 ++:

if (len < 2048) {
		width_accum = BLI_array_alloca(width_accum, len);
		is_malloc = false;
	else {
		width_accum = MEM_mallocN(sizeof(*width_accum) * len, __func__);
		is_malloc = true;

We could avoid these by using _malloca and _freea in windows, where possible.
For GCC there should be a <malloca.h> that conatins these functions.
I can't tell if clang has one, but I guess it has ;)

Another problem the code analysis in VS2013 finds very often is the use of _alloca within loops.
We could/should avoid this... for example by using _malloca ;)

There are many potential memory bugs within blender.
If anyone is interested, I could provide a complete static analysis report.



Event Timeline

Juergen Herrmann (shadowrom) raised the priority of this task from to Needs Triage by Developer.
Juergen Herrmann (shadowrom) updated the task description. (Show Details)
Juergen Herrmann (shadowrom) set Type to Design.

Here is the static analysis report for blender. Looks a bit messy ;)

Campbell Barton (campbellbarton) closed this task as Invalid.EditedApr 24 2014, 10:50 AM

Closing, these kinds of reports are totally full of false positives, I checked 15 or so and were all false positives.

This kind of checking is useful for auditing code, but not useful to manage in the bug tracker.

If you can manage to crash, or get unstable behavior, or find some code which is obviously incorrect, that is fine - report a bug.

Also, we regularly use coverity, cppcheck, smatch and occasionally clangs static analysis tools. From going over reports this log isnt offering new insights.

Note: if you like to use tools to find&fix bugs thats great, but handling these massive reports as bugs is not helping IMHO.