etolabo / kumofs

kumofs is a scalable and highly available distributed key-value store.
http://kumofs.sourceforge.net/
Other
301 stars 16 forks source link

Potential error(e.g., resource leak, deadlock) due to the unreleased lock (logpack_lock(lpk) #28

Open jenny-cheung opened 3 years ago

jenny-cheung commented 3 years ago

Hi, developers, the lock may not be released if the open open(lpk->fname, O_WRONLY|O_APPEND|O_CREAT, 0640) fails. Thank you for your checking. https://github.com/etolabo/kumofs/blob/b0f7ce8263194dbfa92d10ae75849e676e77c067/src/log/logpack.c#L265 https://github.com/etolabo/kumofs/blob/b0f7ce8263194dbfa92d10ae75849e676e77c067/src/log/logpack.c#L252

int logpack_reopen(logpack_t* lpk)
{
    if(logpack_lock(lpk) < 0) { return -1; }

    int tmp = open(lpk->fname, O_WRONLY|O_APPEND|O_CREAT, 0640);
    if(tmp < 0) {
        return -1; // without releasing
    }

    close(lpk->logfd);
    lpk->logfd = tmp;

    logpack_unlock(lpk);
    return 0;
}
jenny-cheung commented 3 years ago

Hi, developers @hirose31 @frsyuki

Any comments would be highly appreciated. Thank you.

Best Regards,