This makes sure we do not dereference a NULL poineter.
Found by covscan.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Nov 26 11:07:09 UTC 2020 on sn-devel-184
SMBC_closedir_ctx(SMBCCTX *context,
SMBCFILE *dir)
{
- TALLOC_CTX *frame = talloc_stackframe();
+ TALLOC_CTX *frame = NULL;
if (!context || !context->internal->initialized) {
errno = EINVAL;
- TALLOC_FREE(frame);
return -1;
}
+ if (dir == NULL) {
+ return 0;
+ }
+
+ frame = talloc_stackframe();
+
if (!SMBC_dlist_contains(context->internal->files, dir)) {
errno = EBADF;
TALLOC_FREE(frame);
DLIST_REMOVE(context->internal->files, dir);
- if (dir) {
-
- SAFE_FREE(dir->fname);
- SAFE_FREE(dir); /* Free the space too */
- }
+ SAFE_FREE(dir->fname);
+ SAFE_FREE(dir); /* Free the space too */
TALLOC_FREE(frame);
return 0;