Suggestion for code analysis

It would be great if resharper c++ can provide suggestion as follows for following situation:

void *buffer = malloc(10*sizeof(int));

free(buffer)

/* provide suggestion stating assign buffer = nullptr as buffer maybe still pointing to already freed memory */ 

 

Thanks,

Dev

2 comments
Comment actions Permalink

Thanks for the idea!

It's not really necessary to assign nullptr to the pointer, but R++ should definitely show when a pointer variable is used after free is called on it - I've filed https://youtrack.jetbrains.com/issue/RSCPP-19576.

0
Comment actions Permalink

Thank you Igor for considering the suggestion.

Just a quick follow up on your comment in which you suggested it's not necessary to assign nullptr, that is true but I have read online stating that sometimes we may encounter dangling pointer problems and its a good defensive style coding practice to assign nullptr after freeing the memory :)

 

Thanks,

Dev

0

Please sign in to leave a comment.