title: Should I check for NULL pointer after malloc and calloc of 2D array in C?
body: <p>OK, I acknowledge that I should check for NULL pointer when mallocing, but what about calloc? Are there any memory leaks possible?</p>
  
  <pre><code>int **initializeMatrix(int *rows, int *cols) {
      int **matrix = malloc((*rows) * sizeof(int*));
      checkNullPointer(matrix);
      for(int i = 0; i &lt; *rows; i++) {
          matrix[i] = calloc(*cols, sizeof(int));
      }
  
      return matrix;
  }
  
  void checkNullPointer(int **ptr) {
      if (ptr == NULL)
          printErrorMessage(memoryErrorMessage, 101);
  }
  </code></pre>