SonarQube is not reporting memory leaks

cpp

(Swetha) #1

Hi,

Below is my code

#include <stdlib.h>

int v_error() {
  int* p = new int;
  *p = 2;

  int* u = (int *)malloc(sizeof(int));
  *u = 4;

  return *p + *u;
}

While i was analysing this code,sonarqube is not reporting memory leak at line 4 but it is reporting memory leak at 7.
Could you please suggest me how to fix this.

Thanks,
Swetha