void list_clear(List* self) { RealList* l_reallist = (RealList*)self; ListNode* l_stand = l_reallist->head; while ( l_stand ) { if ( l_stand->next ) { l_stand=l_stand->next; unref(l_stand->prev->data); mem_destroy(l_stand->prev); } else { unref(l_stand->data); mem_destroy(l_stand); break; } } l_reallist->length=0; l_reallist->head=NULL; l_reallist->tail=NULL; l_reallist->current=NULL; }
void fini_flow_mgr() { // pthread_mutex_destroy(&sw->flow_entry_mutex); mem_destroy(g_gnflow_mempool_id); mem_destroy(g_gninstruction_mempool_id); mem_destroy(g_gnaction_mempool_id); }
void finc_struct_destroy(Object* self) { unref(((FinCStruct*)self)->name); unref(((FinCStruct*)self)->hash_field); mem_destroy (self); }
void list_destroy(Object* self) { RealList* l_reallist = (RealList*)self; list_clear((List*)self); mem_destroy(l_reallist); }
int count_xfreepixmap (const char *fname, int line, Display * display, Pixmap pmap) { mem *m = count_find_and_extract (fname, line, (void *)pmap, C_PIXMAP); if (pmap == None) { show_error("count_xfreepixmap:attempt to free None pixmap in %s:%d", fname, line); return !Success; } if (m == NULL) { show_error ("count_xfreepixmap:attempt in %s:%d to free Pixmap(0x%X) that was never created, or already freed!", fname, line, (unsigned int)pmap); raise( SIGUSR2 ); XFreePixmap (display, pmap ); return !Success; } /* fprintf (stderr,"%s:%s:%d freeing Pixmap(0x%X)\n", __FUNCTION__, fname, line, (unsigned int)pmap); */ XFreePixmap (display, pmap); mem_destroy( (ASHashableValue)NULL, m ); return Success; }
void list_remove_current(List* self) { RealList* l_reallist = (RealList*)self; ListNode* l_stand; if ( l_reallist->current == NULL )return ; l_stand = l_reallist->current; if ( l_stand->prev ) l_stand->prev->next = l_stand->next; else l_reallist->head = l_stand->next; if ( l_stand->next ) { l_stand->next->prev = l_stand->prev; l_reallist->current = l_stand->next; } else { l_reallist->tail = l_stand->prev; l_reallist->current = l_stand->prev; } unref(l_stand->data); mem_destroy(l_stand); l_reallist->length--; }
/* * destroy group module */ void destroy_dc_group_list(){ if(g_dc_group_list_mem_id != NULL){ mem_destroy(g_dc_group_list_mem_id); g_dc_group_list_mem_id = NULL; } return; };
void finc_exit(FinC* self) { unref(self->env); unref(self->sys_func); unref(self->context); mem_destroy(self); }
/* * init group module */ void init_dc_group_list(){ if(g_dc_group_list_mem_id != NULL){ mem_destroy(g_dc_group_list_mem_id); } g_dc_group_list_mem_id = mem_create(sizeof(t_dc_group), DC_GROUP_MAX_NUM); g_current_group_id = DC_GROUP_START_ID; // read from file return; };
int count_xdestroyimage (const char *fname, int line, XImage * image) { mem *m; void *image_data; void *image_obdata; if (image == NULL) { show_error("count_xdestroyimage:attempt to free NULL XImage in %s:%d", fname, line); return BadValue; } image_data = (void *)(image->data); image_obdata = (void *)(image->obdata); if ((m = count_find (fname, line, (void *)image, C_IMAGE)) == NULL) /* can also be of C_MEM type if we allocated it ourselvs */ if ((m = count_find (fname, line, (void *)image, C_MEM)) == NULL) { show_error("count_xdestroyimage:attempt in %s:%d to destroy an XImage that was never created or already destroyed.\n", fname, line); return !Success; } (*image->f.destroy_image) (image); if ((m = count_find_and_extract (fname, line, (void *)image, C_IMAGE)) == NULL) /* can also be of C_MEM type if we allocated it ourselvs */ m = count_find_and_extract (fname, line, (void *)image, C_MEM); if (m) mem_destroy( (ASHashableValue)NULL, m ); /* find and free the image->data pointer if it is in our list */ if( image_data ) if ((m = count_find_and_extract (fname, line, image_data, C_MEM)) != NULL) mem_destroy( (ASHashableValue)NULL, m ); /* find and free the image->obdata pointer if it is in our list */ if( image_obdata ) if ((m = count_find_and_extract (fname, line, image_obdata, C_MEM)) != NULL) mem_destroy( (ASHashableValue)NULL, m ); return Success; }
void countfree (const char *fname, int line, void *ptr) { mem *m ; /* fprintf( stderr, "Service mode = %d, alloca_hash = %p ptr = %p at %s:%d\n", service_mode, allocs_hash, ptr, fname, line );*/ if( service_mode > 0 || allocs_hash == NULL ) return ; if (ptr == NULL) { show_error("countfree:attempt to free NULL memory in %s:%d", fname, line); print_simple_backtrace(); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif return; } m = count_find_and_extract (fname, line, ptr, C_MEM); if (m == NULL) { if( cleanup_mode == 0 ) { show_error( "countfree:attempt in %s:%d to free memory(%p) that was never allocated!", fname, line, ptr); print_simple_backtrace(); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif } return; } #if 0 // this is invalid code!! if (m1->freed > 0) { fprintf (stderr, "%s:mem already freed %d time(s)!\n", __FUNCTION__, m1->freed); fprintf (stderr, "%s:freed from %s:%d\n", __FUNCTION__, (*m1).fname, (*m1).line); fprintf (stderr, "%s:called from %s:%d\n", __FUNCTION__, fname, line); print_simple_backtrace(); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif /* exit (1); */ } else safefree (m1->ptr); m1->freed++; m1->fname = fname; m1->line = line; #else fprintf( stderr, "%s: freeing %p at %s:%d\n", __FUNCTION__, m->ptr, fname, line ); safefree (m->ptr); mem_destroy( (ASHashableValue)NULL, m ); #endif }
static char * test_array_create() { mem_initialize(200, 100); HANDLE *h1 = array_create(5, TYPE_LIST); mu_assert("test_array_create 111", h1->size == sizeof(Array) + 5*sizeof(HANDLE *)); mu_assert("test_array_create 112", ((Array *) h1->data)->len == 5); array_map(count, h1); mu_assert("test_array_map 222", counter == 5); mem_destroy(); return 0; }
void destory_openstack_host(){ if(g_openstack_host_network_id != NULL){ mem_destroy(g_openstack_host_network_id); g_openstack_host_network_id = NULL; } if(g_openstack_host_subnet_id != NULL){ mem_destroy(g_openstack_host_subnet_id); g_openstack_host_subnet_id = NULL; } if(g_openstack_host_port_id != NULL){ mem_destroy(g_openstack_host_port_id); g_openstack_host_port_id = NULL; } if(g_openstack_host_node_id != NULL){ mem_destroy(g_openstack_host_node_id); g_openstack_host_node_id = NULL; } if (g_openstack_security_group_id != NULL) { mem_destroy(g_openstack_security_group_id); g_openstack_security_list = NULL; } if (g_openstack_host_security_id != NULL) { mem_destroy(g_openstack_host_security_id); g_openstack_host_security_id = NULL; } if (g_openstack_security_rule_id != NULL) { mem_destroy(g_openstack_security_rule_id); g_openstack_security_rule_id = NULL; } // clear g_openstack_host_network_list = NULL; g_openstack_host_subnet_list = NULL; g_openstack_host_port_list = NULL; g_openstack_security_list = NULL; return; };
void init_openstack_host(){ if(g_openstack_host_network_id != NULL){ mem_destroy(g_openstack_host_network_id); } g_openstack_host_network_id = mem_create(sizeof(openstack_network), OPENSTACK_NETWORK_MAX_NUM); if(g_openstack_host_subnet_id != NULL){ mem_destroy(g_openstack_host_subnet_id); } g_openstack_host_subnet_id = mem_create(sizeof(openstack_subnet), OPENSTACK_SUBNET_MAX_NUM); if(g_openstack_host_port_id != NULL){ mem_destroy(g_openstack_host_port_id); } g_openstack_host_port_id = mem_create(sizeof(openstack_port), OPENSTACK_PORT_MAX_NUM); if(g_openstack_host_node_id != NULL){ mem_destroy(g_openstack_host_node_id); } g_openstack_host_node_id = mem_create(sizeof(openstack_node), OPENSTACK_NODE_MAX_NUM); if (g_openstack_security_group_id != NULL) { mem_destroy(g_openstack_security_group_id); } g_openstack_security_group_id = mem_create(sizeof(openstack_security), OPENSTACK_SECURITY_GROUP_MAX_NUM); if (g_openstack_host_security_id != NULL) { mem_destroy(g_openstack_host_security_id); } g_openstack_host_security_id = mem_create(sizeof(openstack_node), OPENSTACK_HOST_SECURITY_MAX_NUM); if (g_openstack_security_rule_id != NULL) { mem_destroy(g_openstack_security_rule_id); } g_openstack_security_rule_id = mem_create(sizeof(openstack_security_rule), OPENSTACK_SECURITY_RULE_MAX_NUM); g_openstack_host_network_list = NULL; g_openstack_host_subnet_list = NULL; g_openstack_host_port_list = NULL; return; };
int count_xfreegc (const char *fname, int line, Display * display, GC gc) { mem *m = count_find_and_extract (fname, line, (void *)gc, C_GC); if (gc == None) { show_error( "count_xfreegc:attempt to free None GC in %s:%d", fname, line); return !Success; } if (m == NULL) { show_error( "count_xfreegc:attempt in %s:%d to free a GC (%p)that was never created or already destroyed!", fname, line, gc); return !Success; } XFreeGC (display, gc); mem_destroy( (ASHashableValue)NULL, m ); return Success; }
int count_xfree (const char *fname, int line, void *data) { mem *m = count_find_and_extract (fname, line, (void *)data, C_XMEM); if (data == NULL) { show_error("count_xfree:attempt to free NULL X memory in %s:%d", fname, line); return !Success; } if (m == NULL) { show_error("count_xfree:attempt in %s:%d to free X memory (%p) that was never allocated or already freed!", fname, line, data); return !Success; } XFree (data); mem_destroy( (ASHashableValue)NULL, m ); return Success; }
ADT list_take_current(List* self) { RealList* l_reallist = (RealList*)self; ListNode* l_stand; ADT rtn = NULL; if ( l_reallist->current == NULL )return NULL; l_stand = l_reallist->current; if ( l_stand->prev ) l_stand->prev->next = l_stand->next; else l_reallist->head = l_stand->next; if ( l_stand->next ) l_stand->next->prev = l_stand->prev; else l_reallist->tail = l_stand->prev; if ( l_stand->next )l_reallist->current = l_stand->next; else l_reallist->current = l_stand->prev; mem_destroy(l_stand); l_reallist->length--; return addref(ADT, rtn); }
int main() { COMMAND cmd; ARG args = { 0, 0 }; void *res, *addr; ID id; size_t size; init(); /* initialisation de l'interpreteur */ while (1) { #ifdef DEBUG printf("memshell-main: debut de la boucle de l'interpreteur\n"); #endif printf(PROMPT); cmd = read_command(&args); switch (cmd) { case INIT: printf("Réinitialisation de la mémoire (%d octets)...", HEAP_SIZE); mem_init(); printf("OK\n"); break; case SHOW: printf ("Mémoire initialement disponible : %d octets débutant en %p\n", HEAP_SIZE, zone_memoire); break; case USED: used(); break; case ALLOC: res = mem_alloc(args.size); /* si une erreur a lieu, on affiche 0 */ if (res == NULL) { printf ("Erreur : échec de l'allocation (fonction mem_alloc, retour=NULL)\n"); } else { id = get_id(res, args.size); if (id == 0) { /* s'il ne reste pas d'id libre on affiche 0 et on libere le bloc */ printf ("Erreur : nombre maximum d'allocations atteint/n"); mem_free(res, args.size); } else { /* pas de probleme, affichage de la zone allouée */ printf("%ld 0x%lX\n", id, (unsigned long) (res - (void *) zone_memoire)); } } break; case DESTROY: mem_destroy(); break; case FREE: if (get_info_from_id(args.id, &addr, &size) == -1) /* erreur dans la valeur de l'id */ printf("Erreur : identificateur de bloc incorrect\n"); else { /* liberation du bloc concerne */ mem_free(addr, size); /* liberation de l'id */ remove_id(args.id); /* NB : dans le cas normal, on n'affiche rien */ } break; case HELP: help(); break; case EXIT: mem_destroy(); goto end; case ERROR: printf("Commande incorrecte\n"); break; } } end: return 0; }
void cleanup() { mem_destroy(&mem); }
/* *** */ static int bam(const char *scriptfile, const char **targets, int num_targets) { struct CONTEXT context; int build_error = 0; int setup_error = 0; int report_done = 0; /* build time */ time_t starttime = time(0x0); /* create the cache and tmp directory */ file_createdir(".bam"); /* zero out and create memory heap, graph */ memset(&context, 0, sizeof(struct CONTEXT)); context.graphheap = mem_create(); context.deferredheap = mem_create(); context.graph = node_graph_create(context.graphheap); context.exit_on_error = option_abort_on_error; context.buildtime = timestamp(); /* create lua context */ /* HACK: Store the context pointer as the userdata pointer to the allocator to make sure that we have fast access to it. This makes the context_get_pointer call very fast */ context.lua = lua_newstate(lua_alloctor_malloc, &context); /* install panic function */ lua_atpanic(context.lua, lf_panicfunc); /* load cache (thread?) */ if(option_no_cache == 0) { /* create a hash of all the external variables that can cause the script to generate different results */ hash_t cache_hash = 0; char hashstr[64]; int i; for(i = 0; i < option_num_scriptargs; i++) cache_hash = string_hash_add(cache_hash, option_scriptargs[i]); string_hash_tostr(cache_hash, hashstr); sprintf(cache_filename, ".bam/%s", hashstr); event_begin(0, "cache load", cache_filename); context.cache = cache_load(cache_filename); event_end(0, "cache load", NULL); } /* do the setup */ setup_error = bam_setup(&context, scriptfile, targets, num_targets); /* done with the loopup heap */ mem_destroy(context.deferredheap); /* close the lua state */ lua_close(context.lua); /* do actions if we don't have any errors */ if(!setup_error) { event_begin(0, "prepare", NULL); build_error = context_build_prepare(&context); event_end(0, "prepare", NULL); if(!build_error) { event_begin(0, "prioritize", NULL); build_error = context_build_prioritize(&context); event_end(0, "prioritize", NULL); } if(!build_error) { if(option_debug_nodes) /* debug dump all nodes */ node_debug_dump(context.graph); else if(option_debug_nodes_detailed) /* debug dump all nodes detailed */ node_debug_dump_detailed(context.graph); else if(option_debug_jobs) /* debug dump all jobs */ node_debug_dump_jobs(context.graph); else if(option_debug_joblist) /* debug dumps the joblist */ context_dump_joblist(&context); else if(option_debug_dot) /* debug dump all nodes as dot */ node_debug_dump_dot(context.graph, context.target); else if(option_debug_jobs_dot) /* debug dump all jobs as dot */ node_debug_dump_jobs_dot(context.graph, context.target); else if(option_dry) { } else { /* run build or clean */ if(option_clean) { event_begin(0, "clean", NULL); build_error = context_build_clean(&context); event_end(0, "end", NULL); } else { event_begin(0, "build", NULL); build_error = context_build_make(&context); event_end(0, "build", NULL); report_done = 1; } } } } /* save cache (thread?) */ if(option_no_cache == 0 && setup_error == 0) { event_begin(0, "cache save", cache_filename); cache_save(cache_filename, context.graph); event_end(0, "cache save", NULL); } /* clean up */ mem_destroy(context.graphheap); free(context.joblist); cache_free(context.cache); /* print final report and return */ if(setup_error) { /* no error message on setup error, it reports fine itself */ return setup_error; } else if(build_error) printf("%s: error: a build step failed\n", session.name); else if(report_done) { if(context.num_jobs == 0) printf("%s: targets are up to date already\n", session.name); else { time_t s = time(0x0) - starttime; if(s <= 1) printf("%s: done\n", session.name); else printf("%s: done (%d:%.2d)\n", session.name, (int)(s/60), (int)(s%60)); } } return build_error; }