LCOV - code coverage report
Current view: top level - t - broken-alloc.c (source / functions) Hit Total Coverage
Test: PB-C-TEXT Code Coverage Lines: 16 17 94.1 %
Date: 2014-09-08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <sys/types.h>
       2             : #include <signal.h>
       3             : #include <stdio.h>
       4             : #include <string.h>
       5             : #include <stdlib.h>
       6             : #include <unistd.h>
       7             : #include <protobuf-c/protobuf-c.h>
       8             : 
       9             : static void *
      10       21239 : broken_alloc(void *allocator_data, size_t size)
      11             : {
      12             :   static int not_broken = -1;
      13       21239 :   char *$BROKEN_MALLOC = getenv("BROKEN_MALLOC");
      14             : 
      15       21239 :   if (not_broken < 0 && $BROKEN_MALLOC) {
      16         309 :     not_broken = atoi($BROKEN_MALLOC);
      17             :   }
      18       21239 :   if ($BROKEN_MALLOC && not_broken > 0) {
      19       19543 :     not_broken--;
      20             :   }
      21       21239 :   if (not_broken) {
      22       20904 :     return malloc(size);
      23             :   } else {
      24         335 :     char *$BROKEN_MALLOC_SENTINAL = getenv("BROKEN_MALLOC_SENTINAL");
      25             : 
      26         335 :     if ($BROKEN_MALLOC_SENTINAL) {
      27         335 :       unlink($BROKEN_MALLOC_SENTINAL);
      28             :     }
      29         335 :     if (getenv("BROKEN_MALLOC_SEGV")) {
      30           0 :       kill(getpid(), SIGSEGV);
      31             :     }
      32         335 :     return NULL;
      33             :   }
      34             : }
      35             : 
      36             : static void
      37       17563 : broken_free(void *allocator_data, void *data)
      38             : {
      39       17563 :   free(data);
      40       17563 : }
      41             : 
      42             : ProtobufCAllocator broken_allocator = {
      43             :         .alloc = &broken_alloc,
      44             :         .free = &broken_free,
      45             :         .allocator_data = NULL,
      46             : };

Generated by: LCOV version 1.10