Multiple choice technology security

Which line of the code should be deleted to remove vulnerability? int main(int argc,char* argv[]) { int ptr1=new int; if(ptr1==NULL) exit(1); int *ptr2=new int; if(ptr2==NULL) exit(1); char j; j=argv[1]; int k=atoi(j); if (j==0){ Ptr1=&k; delete ptr2; /1/ } else { Ptr2=&k; } delete ptr1; /2/ delete ptr2; /3/ return 0; }

  1. delete ptr2; (within if loop) AND delete ptr1;

  2. delete ptr1; AND delete ptr2; (outside if loop )

  3. delete ptr2; (within if loop)

  4. delete ptr2; (outside if loop )

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In the if (j==0) branch, ptr2 is already deleted (line 1). Then outside the if, it's deleted again (line 3), double-free vulnerability. Removing line 1's delete fixes it. The code has typos (Ptr1/Ptr2 vs ptr1/ptr2) but the logic error is clear.