title: Segmentation error on Assignment to returned pointer
body: <p>I am curious as to why would assigning a returned pointer to a new pointer variable cause a segmentation fault? However, passing a pointer into the pop() function as a double pointer would not cause any error.</p>
  <p>The code below is for testing purposes, I am trying to implement a queue here.</p>
  <pre><code>void push(struct node **head, Task * newTask) {
      struct node* temp = malloc(sizeof(struct node));
      temp-&gt;task = newTask;
      temp-&gt;next = NULL;
      struct node* curr = *head;
      if (*head == NULL) {
          puts(&quot;Entered here&quot;);
          temp-&gt;next = *head;
          *head = temp;
      } else {
          while (curr-&gt;next != NULL) {
              curr = curr-&gt;next;
          }
          curr-&gt;next = temp;
      }
  }
  
  Task* pop(struct node** head, Task** returnTask) {
      struct node* returnNode = *head;
      *returnTask = returnNode-&gt;task;
      *head = returnNode-&gt;next;
      free(returnNode);
      printf(&quot;%s\n&quot;, (*returnTask)-&gt;name);
      return *returnTask;
  }
  </code></pre>
  <p>Below is the code that's causing segmentation fault (returnedTask)</p>
  <p>Error: Segmentation fault (core dumped)</p>
  <pre><code>void schedule() {
      struct node* queue = NULL;
      Task* currTask = pickNextTask(); //Returns a Task
      push(&amp;queue, currTask);
      Task* newTask = NULL;
      Task* returnedTask = pop(&amp;queue, &amp;newTask);
      printf(&quot;%s&quot;, newTask-&gt;name); //Runs fine
      printf(&quot;%s&quot;, returnedTask-&gt;name);  //Segmentation fault
  }
  </code></pre>
  <p>Task.h definition</p>
  <pre><code>#ifndef TASK_H
  #define TASK_H
  
  // representation of a task
  typedef struct task {
      char *name;
      int tid;
      int priority;
      int burst;
  } Task;
  
  #endif
  </code></pre>
  <p>Node</p>
  <pre><code>struct node {
      Task *task;
      struct node *next;
  };
  </code></pre>