Skip to content

fix resource leaks reported by Coverity#387

Merged
kdudka merged 2 commits intologrotate:masterfrom
kdudka:coverity
May 3, 2021
Merged

fix resource leaks reported by Coverity#387
kdudka merged 2 commits intologrotate:masterfrom
kdudka:coverity

Conversation

@kdudka
Copy link
Member

@kdudka kdudka commented May 3, 2021

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/config.c:2116: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.
# 2114|       munmap(buf, length);
# 2115|       close(fd);
# 2116|->     return logerror;
# 2117|   error:
# 2118|       /* free is a NULL-safe operation */

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/config.c:2122: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.
# 2120|       munmap(buf, length);
# 2121|       close(fd);
# 2122|->     return 1;
# 2123|   }
# 2124|   

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
logrotate-3.18.0.18_7a4d/logrotate.c:1922: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.
# 1920|               if (rotNames->disposeName == NULL) {
# 1921|                   message_OOM();
# 1922|->                 return 1;
# 1923|               }
# 1924|           }

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
logrotate-3.18.0.18_7a4d/logrotate.c:1931: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.
# 1929|               message_OOM();
# 1930|               rotNames->firstRotated = NULL;
# 1931|->             return 1;
# 1932|           }
# 1933|   

@cgzones
Copy link
Member

cgzones commented May 3, 2021

LGTM 👍

p.s.: are you using a special version of Coverity, since the scan service for open source projects does not find these issues (I scan occasionally at https://scan.coverity.com/projects/cgzones-logrotate)?

@kdudka
Copy link
Member Author

kdudka commented May 3, 2021

Thanks for review! Yes, we use our own instance of Coverity at Red Hat. This scan ran with the 2020.12 version of Coverity, which probably had (an improved) built-in model of the asprintf() function, compared to what scan.coverity.com uses now.

kdudka added 2 commits May 3, 2021 21:21
This eliminates the following reports by Coverity:

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/config.c:2116: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/config.c:2122: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.

Closes: logrotate#387
This eliminates the following reports by Coverity:

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
logrotate-3.18.0.18_7a4d/logrotate.c:1922: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK (CWE-772):
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
logrotate-3.18.0.18_7a4d/logrotate.c:1931: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.

Closes: logrotate#387
@kdudka kdudka merged commit 85bc130 into logrotate:master May 3, 2021
@kdudka kdudka deleted the coverity branch May 25, 2022 07:33
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