SonarQube is not reporting memory leaks

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

Hi @swetha,

we apologise but we missed your topic. We anyway would like to recommend you trying the latest version of our analyser which is shipped in SonarQube 7.5 or available on SonarCloud.

1 Like

Hi,

Sonarqube not detecting memory leaks in the code even though all rules are activated in the quality profile .I am using sonarqube 7.6
Can you suggest how to fix this

Below is my code

#include <stdio.h>
#include <unistd.h>
#define BUFSIZE1 512
#define BUFSIZE2 ((BUFSIZE1/2) - 8)

int main(int argc, char **argv) {
char *buf1R1;
char *buf2R1;
char *buf1R2;
buf1R1 = (char *) malloc(BUFSIZE2);
buf2R1 = (char *) malloc(BUFSIZE2);
buf1R2 = (char *) malloc(BUFSIZE1);
strncpy(buf1R2, argv[1], BUFSIZE1-1);
}

Thanks

Hi @Dhanush_KC,

could you please open a new thread for your request?