leetcode- c回答堆释放后使用错误

时间:2019-03-18 15:22:19

标签: c

我是CI的新手,请提供leetcode的问题20的答案。我实现了堆栈来解决问题。我想知道我在哪里错了。我得到了有关该错误的一些信息。据说那里有一个内存泄漏。我已经检查了,无法解决。 代码如下:

<template>
  <div id="signup-form-con" v-if="!connected">
    <form id="signup-form" @submit.prevent>
      <input v-model='firstName' type="text" id="signup-name" placeholder='First name'><br />
      <input v-model='lastName' type="text" id="signup-surname" placeholder='Last name'><br />
      <input v-model='student' type="checkbox"><span class='checkbox-label'>Student</span>
      <input v-model='teacher' type="checkbox"><span class='checkbox-label'>Teacher</span><br />
      <input v-model='email' type="email" id="signup-email"><br />
      <input v-model='password' type="password" placeholder='Password'>
      <input v-model='confirmed' type="password" placeholder='Confirm'><br />
      <span>Sign in instead</span>
      <button @click='EmailSignIn'>Next</button>
    </form>
    <div class="auto-signup">
      <span id="or-use">Or use</span>
      <div class="buttons">
        <button id="google-signup" @click='GoogleSignIn'>
          <img src="" alt="" id="google-img-signup">
        </button>
        <button id="facebook-signup" @click='FacebookSignIn'>
          <img src="" alt="" id="fb-img-signup">
        </button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "Form",
  props: {
    connected: false
  },
  data: function() {
    return {
      localUser: null,
      firstName: null,
      lastName: null,
      student: false,
      teacher: false,
      email: null,
      password: null,
      confirmed: null
    }
  },
  methods: {

    EmailSignIn: function() {
      
    firebase.auth().createUserWithEmailAndPassword(this.email, this.password).catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorMessage);

            firebase.auth().onAuthStateChanged( (user) => {
              if (user) {
                // If already signed in
                const db = firebase.firestore();
                // THE BUG - cannot access this.localUser
                this.localUser = user;
                console.log(this.localUser);
                db.collection("users").doc(this.localUser.uid).set({
                    firstName: this.firstName,
                    lastName: this.lastName,
                    student: this.student,
                    teacher: this.teacher,
                    email: this.email,
                    password: this.password
                })
                .then(function() {
                    console.log("Document successfully written!");
                })
                .catch(function(error) {
                    console.error("Error writing document: ", error);
                });
              }
            })

          }).then(() => {

          })
    }

</script>

<style scoped lang="sass"></style>

错误如下:

    struct linestack{
    char element;
    struct linestack *next;
};

struct linestack *push(struct linestack *head,char c);
char pop(struct linestack *head);

bool isValid(char* s) {
    char *p = s;
    char c;
    struct linestack* head;
    while(*p!='\0'){
        if(*p=='('||*p=='{'||*p=='['){
            head = push(head,*p);
        }else{
            if(head)
                 c = pop(head);
            else
                return false;
            if(*p=='('&&c!=')')
                return false;
            if(*p=='['&&c!=']')
                return false;
            if(*p=='{'&&c!='}')
                return false;
        }
        p++;
    }
    return true;
}


struct linestack* push(struct linestack *head,char c){
    struct linestack* line = (struct linestack*)malloc(sizeof(struct linestack));
    line->element = c;
    line->next = head;
    head = line;
    return head;
}

char pop(struct linestack *head){
    char res;
    if(head){
        struct linestack* p = head;
        res = head->element;
        head = head->next;
        free(p);
    }
    return res;
}

0 个答案:

没有答案