close a bunch of fd leaks in error paths

found by coverity.
This commit is contained in:
Oswald Buddenhagen 2014-04-12 12:46:36 +02:00
parent dec5f73f57
commit df29c592d1
2 changed files with 11 additions and 3 deletions

View File

@ -219,8 +219,10 @@ maildir_list_recurse( store_t *gctx, int isBox, int *flags, const char *inbox,
const char *ent = de->d_name; const char *ent = de->d_name;
pl = pathLen + nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "%s", ent ); pl = pathLen + nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "%s", ent );
if (inbox && !memcmp( path, inbox, pl ) && !inbox[pl]) { if (inbox && !memcmp( path, inbox, pl ) && !inbox[pl]) {
if (maildir_list_inbox( gctx, flags ) < 0) if (maildir_list_inbox( gctx, flags ) < 0) {
closedir( dir );
return -1; return -1;
}
} else { } else {
if (*ent == '.') { if (*ent == '.') {
if (!isBox) if (!isBox)
@ -238,10 +240,12 @@ maildir_list_recurse( store_t *gctx, int isBox, int *flags, const char *inbox,
} }
} }
nl = nameLen + nfsnprintf( name + nameLen, _POSIX_PATH_MAX - nameLen, "%s", ent ); nl = nameLen + nfsnprintf( name + nameLen, _POSIX_PATH_MAX - nameLen, "%s", ent );
if (maildir_list_recurse( gctx, 1, flags, inbox, path, pl, name, nl ) < 0) if (maildir_list_recurse( gctx, 1, flags, inbox, path, pl, name, nl ) < 0) {
closedir( dir );
return -1; return -1;
} }
} }
}
closedir (dir); closedir (dir);
return 0; return 0;
} }
@ -677,6 +681,7 @@ maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
ctx->db->err( ctx->db, ret, "Maildir error: db->get()" ); ctx->db->err( ctx->db, ret, "Maildir error: db->get()" );
mbork: mbork:
maildir_free_scan( msglist ); maildir_free_scan( msglist );
closedir( d );
goto bork; goto bork;
} }
uid = INT_MAX; uid = INT_MAX;

View File

@ -208,8 +208,10 @@ convert( const char *box, int altmap )
nfsnprintf( buf2 + bl, sizeof(buf2) - bl, "%.*s,U=%d%s", ml, e->d_name, uid, ru ); nfsnprintf( buf2 + bl, sizeof(buf2) - bl, "%.*s,U=%d%s", ml, e->d_name, uid, ru );
} }
if (rename( buf, buf2 )) { if (rename( buf, buf2 )) {
if (errno == ENOENT) if (errno == ENOENT) {
closedir( d );
goto again; goto again;
}
sys_error( "Cannot rename %s to %s", buf, buf2 ); sys_error( "Cannot rename %s to %s", buf, buf2 );
ebork: ebork:
closedir( d ); closedir( d );
@ -224,6 +226,7 @@ convert( const char *box, int altmap )
close( dfd ); close( dfd );
if (rename( tdpath, dpath )) { if (rename( tdpath, dpath )) {
sys_error( "Cannot rename %s to %s", tdpath, dpath ); sys_error( "Cannot rename %s to %s", tdpath, dpath );
close( sfd );
return 1; return 1;
} }
if (unlink( spath )) if (unlink( spath ))