[MXS-350] Return value of realloc must not be assigned to provided pointer. Created: 2015-09-04 Updated: 2017-11-17 Resolved: 2016-06-16 |
|
| Status: | Closed |
| Project: | MariaDB MaxScale |
| Component/s: | Core |
| Affects Version/s: | 1.1.0, 1.2.0, 1.3.0, 1.4.0 |
| Fix Version/s: | 2.1.0 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Johan Wikman | Assignee: | Johan Wikman |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Sprint: | 2016-12 | ||||||||||||
| Description |
|
If realloc fails it returns NULL. Thus, in a situation like
if realloc fails, the previously allocated memory will leak. Realloc must be used like:
|
| Comments |
| Comment by Johan Wikman [ 2015-09-05 ] | |||||||||||||||||||||
|
This cannot be done mechanically, since there is code that simply assumes that memory allocations will not fail. Consequently, larger re-factoring is needed. | |||||||||||||||||||||
| Comment by Johan Wikman [ 2015-09-07 ] | |||||||||||||||||||||
|
Lowering priority to minor. Not using realloc the way it is supposed to be used is clearly a bug, but one which in practice will not manifest itself. Consequently, this is better handled as part of general refactoring to be done post 1.3. | |||||||||||||||||||||
| Comment by Johan Wikman [ 2016-02-29 ] | |||||||||||||||||||||
|
Again lowering to minor. The usage is wrong but in the environments were MaxScale will be used, malloc, realloc and calloc will in practice not fail but return a valid pointer. Later, when the memory is actually accessed, the OOM killer might kill MaxScale but checking for the return value will not save from that. | |||||||||||||||||||||
| Comment by Johan Wikman [ 2016-06-16 ] | |||||||||||||||||||||
|
All calls to realloc corrected except where the function calling realloc cannot fail, in which case the use of realloc has been replaced with mxs_realloc that takes the process down if the allocation fails. I.e. grepping for mxs_realloc reveals places that may need refactoring. | |||||||||||||||||||||
| Comment by Wagner Bianchi (Inactive) [ 2017-11-16 ] | |||||||||||||||||||||
|
Another way to generate an error like this one is calling a non-existing configuration file, like below:
|