void * vmalloc ( size_t size) { void * x; Memcontrol *M; verify_memory (size+2*sizeof (Memcontrol)); if ( size==0) return NULL; /*crash ("\n0 bytes in vmalloc\n");*/ else { x= malloc (size + 2*sizeof (Memcontrol)); //x=dlmalloc (size + 2*sizeof (Memcontrol)); if ( x==NULL) { printf_exit (EXIT_FAILURE,stderr, "\nFAILED TO ALLOCATE REQUIRED MEMORY (vmalloc)\n"); } else { M=x; M[0].size=size; M[0].size_element=0; sprintf ( M[0].check, "dy"); M+=2; x=M; return x; } } return NULL;}
void *vmalloc(size_t size) { void *x; Memcontrol *M; verify_memory(size+2*sizeof(Memcontrol)); if(size==0) { return NULL; /*crash ("\n0 bytes in vmalloc\n");*/ } else { x= malloc(size + 2*sizeof(Memcontrol)); if(x==NULL){ fprintf(stderr, "ERROR - FAILED TO ALLOCATE REQUIRED MEMORY (vmalloc)\n"); exit(-1); } else { M = (Memcontrol *) x; M[0].size=size; M[0].size_element=0; sprintf(M[0].check, "dy"); M+=2; x=M; return x; } } return NULL; }
FxB_Node *FxB_Node_create(void *value) { FxB_Node *node = fx_alloc(FxB_Node); verify_memory(node); fxb_node_value(node) = value; return node; error: return NULL; }
/**Funkcja weryfikuje poprawność podpisu xades. Weryfikacja obejmuje obliczenia matematyczne * oraz weryfikację poszczególnych pól formualarza i certyfikatu. * \retval -109 Certyfikat poza terminem ważności. * */ long xades_verify(const char * buffer, const long buffer_len, GenBuf_t *timestamp) { xmlSecKeysMngrPtr mngr = NULL; long ret = 0; long status = 0; if (buffer == NULL) { PRINT_DEBUG("Wrong argument 1!\n"); return ERR_arg+1; } if (timestamp == NULL) { PRINT_DEBUG("Wrong argument 3!\n"); return ERR_arg+3; } /* Init libxml and libxslt libraries */ xades_init(); /* create keys manager and load trusted certificates */ mngr = xmlSecKeysMngrCreate(); if(mngr == NULL) { PRINT_DEBUG( "Error: failed to create keys manager.\n"); ret = -1; } if (mngr != NULL) { status = xmlSecCryptoAppDefaultKeysMngrInit(mngr); if(status < 0) { PRINT_DEBUG( "Error: failed to initialize keys manager: %li\n",status); ret = -2; } else { status = verify_memory(mngr,buffer, buffer_len); if (status != 0) { PRINT_ERROR("XAdES memory verification result: %li\n",status); ret = -4; } status = verify_fields(buffer, buffer_len, timestamp); if (status < 0) { PRINT_ERROR("XAdES tags verification result: %li\n", status); ret = -100+status; } } } xmlSecKeysMngrDestroy(mngr); xades_destroy(); return ret; }
FxI_Object *FxI_Object_create(FxI_Interpreter *interpreter, FxI_Object *klass) { FxI_Object *object = fx_alloc(FxI_Object); verify_memory(object); FxB_HashMap *attributes = FxB_HashMap_create(FXN_OBJECT_ATTRIBUTE_HASHMAP_SIZE); verify(attributes); fxi_object_class(object) = klass; fxi_object_attributes(object) = attributes; return object; error: if (object) { fx_pfree(object); } return NULL; }
FxI_MethodGroup *FxI_MethodGroup_create(char *method_name) { FxI_MethodGroup *method_group = fx_alloc(FxI_MethodGroup); verify_memory(method_group); fxi_method_group_name(method_group) = method_name; FxB_List *functions = FxB_List_create(); verify(functions); fxi_method_group_functions(method_group) = functions; return method_group; error: if (method_group) { fx_pfree(method_group); } return NULL; }
void vfree(void *p) { Memcontrol *M; size_t size; if(!p) return; else { M= (Memcontrol*) p; M-=2; size=M[0].size; p=M; free(p); verify_memory(-(size+2*sizeof(Memcontrol))); } }
void run_allocation_test(WhichAlloc wa, uint32_t numallocs) { void **table = calloc(numallocs, sizeof(void*)); for (int i = 0; i < numallocs; i++) { /* Random allocation size */ uint32_t numwords = 1 + rand() % (2 << 15); /* Allocate the memory and save the pointer in table */ void *addr = 0; if (wa == USE_MALLOC) { addr = malloc(WSIZE * numwords); } else if (wa == USE_CALLOC) { addr = calloc(numwords, WSIZE); } else if (wa == USE_REALLOC) { addr = realloc(0, WSIZE * numwords); } assert(addr); table[i] = addr; /* Initialize allocated memory */ init_memory(addr, numwords); } /* To stir things up, allocate, init and release some memory */ #define NSTIR 10 void *stir_table[NSTIR]; for (int i = 0; i < NSTIR; ++i) { uint32_t numwords = 1 + rand() % (2 << 18); void *addr = malloc(WSIZE * numwords); init_memory(addr, numwords); stir_table[i] = addr; } for (int i = 0; i < NSTIR; ++i) { free(stir_table[i]); } /* When all was allocated, verify that all memory looks as expected */ for (int i = 0; i < numallocs; i++) { verify_memory(table[i]); } /* Finally, free all allocated memory */ for (int i = 0; i < numallocs; i++) { free(table[i]); } free(table); }
void *vrealloc ( void *p, size_t size) { void *x; Memcontrol *M; size_t i_size; int a; if ( p==NULL) { x=vmalloc (size); memset (x, 0, size); return x; } else { M=p; M-=2; i_size=M[0].size; p=M; if ( size<=0){return NULL;vfree (p);return NULL;} else { verify_memory (size - i_size); x=realloc ( p, size+2*sizeof(Memcontrol)); if ( x==NULL){crash ( "\nFAILED TO ALLOCATE REQUIRED MEMORY (realloc)\n");return NULL;} M=x; M[0].size=size; M+=2; x=M; for ( a=i_size; a< size; a++)((char*)x)[a]=0; return x; } } return NULL; }