Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Does GCC have features to detect use-after-free bugs?

Here is my code snippet:

#include <stdlib.h>
#include <stdio.h>

typedef struct node
{
    char key;          // value
    struct node *next; // pointer to the next element
} Node;

int main(void)
{
    Node *n = malloc(sizeof(Node));
    n->key = 'K';
    n->next = NULL;

    free(n);

    printf("%c\n", n->key);
}

When the above snippet is compiled and run...

ganningxu@Gannings-Computer:~/test$ gcc test_faults.c -o test_faults; ./test_faults
K

ganningxu@Gannings-Computer:~/test$ clang test_faults.c -o test_faults; ./test_faults
K

There are no compiler warnings or errors when the freed memory is accessed. Is there any way to force the compiler to show such errors?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When compiling with GCC, you can use -fsanitize=address so that “Memory access instructions are instrumented to detect out-of-bounds and use-after-free bugs.” This will of course affect program performance, and it may also change the program behavior if there are bugs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!