'Address Sanitizer: Deadly Signal

I was trying to solve 'Valid Parentheses' problem from leetcode. I am getting run time error after adding 'stackname.empty()' function. I tried several times in different ways but getting the same error. What could be the issue? My code is added below:

class Solution {
public:
    bool isValid(string s) {
        stack<char>brac;
        for(int i = 0; i<=s.length()-1;i++){
            if(s[i]=='('){
                brac.push('(');
            }
            else if(s[i]=='{'){
                brac.push('{');
            }
            else if(s[i]=='['){
                brac.push('[');
            }
            else if(s[i]==')'){
                if (brac.top()!='('){
                    return false;
                }
                else{
                    brac.pop();
                }
            }
            else if(s[i]=='}'){
                if (brac.top()!='{'){
                    return false;
                }
                else{
                    brac.pop();
                }
            }
            else if(s[i]==']'){
                if (brac.top()!='['){
                    return false;
                }
                else{
                    brac.pop();
                }
            }    
        }
        
        if(!brac.empty()){
            return false;
        }
        else{
            return true;
        }
        
    }
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source