/* * del_arginfo * ( called by _free_args() ) * */ void del_arginfo(APTR data) { struct arginfo *arg = (struct arginfo *) data; if (arg) { /* type dependent cleanup */ if (arg->ai_type == ARG_ENUM) ufree(arg->ai_misc1.ai_enum); /* cleanup entities */ ufree(arg->ai_id); ufree(arg->ai_help); arg->ai_type = 0; arg->ai_dest = NULL; arg->ai_func = NULL; /* cleanup whole structure */ ufree(arg); } }
static void hash_ctx_destroy_cb(struct hash_ctx *ctx) { ufree(ctx->name); ufree(ctx->ctx); ufree(ctx); }
VOID del_estr(EXPSTR * es) { #if DEBUG_UGLY_EXPSTR if (es) { if (es->es_data) { #if DEBUG_UGLY_EXPSTR == 2 STRARR s[17]; strncpy(s, es->es_data, 17); s[16] = 0; D(fprintf(stderr, DEXP "del_estr(%p,`%s')\n", es, s)); umem_wallcheck("del_estr()"); #endif } else { D(fprintf(stderr, DEXP "attempt to free null-data-estr\n")); } } else { #if DEBUG_UGLY_EXPSTR == 2 D(fprintf(stderr, DEXP "attempt to free null-estr\n")); #endif } #endif if (es) { ufree(es->es_data); es->es_len = 0; es->es_size = 0; es->es_step = 0; ufree(es); } }
void lpp_load_sol(LPP *lpp, LPX *prob) { int i, j, ref, stat; double prim, dual; insist(lpp->m == lpx_get_num_rows(prob)); insist(lpp->n == lpx_get_num_cols(prob)); insist(lpp->orig_dir == lpx_get_obj_dir(prob)); insist(lpx_get_status(prob) != LPX_UNDEF); for (i = 1; i <= lpp->m; i++) { lpx_get_row_info(prob, i, &stat, &prim, &dual); ref = lpp->row_ref[i]; insist(1 <= ref && ref <= lpp->nrows); insist(lpp->row_stat[ref] == 0); lpp->row_stat[ref] = stat; lpp->row_prim[ref] = prim; lpp->row_dual[ref] = (lpp->orig_dir == LPX_MIN ? + dual : - dual); } for (j = 1; j <= lpp->n; j++) { lpx_get_col_info(prob, j, &stat, &prim, &dual); ref = lpp->col_ref[j]; insist(1 <= ref && ref <= lpp->ncols); insist(lpp->col_stat[ref] == 0); lpp->col_stat[ref] = stat; lpp->col_prim[ref] = prim; lpp->col_dual[ref] = (lpp->orig_dir == LPX_MIN ? + dual : - dual); } ufree(lpp->row_ref), lpp->row_ref = NULL; ufree(lpp->col_ref), lpp->col_ref = NULL; return; }
void ds_msg_free_handle(ds_msg_handle_t *handle) { _check_init(handle); if (handle->parts) { int i; for (i = 0; i < handle->hdr.nParts; i++) { if (handle->parts[i].buf) { ufree(handle->parts[i].buf); handle->parts[i].buf = NULL; handle->parts[i].n_buf_alloc = 0; } } ufree(handle->parts); handle->parts = NULL; handle->n_parts_alloc = 0; } if (handle->assembled_msg) { ufree (handle->assembled_msg); handle->assembled_msg = NULL; handle->n_assembled_alloc = 0; } handle->init_flag = 0; }
static void new_coef(struct dsa *dsa, int i, int j, double aij) { /* add new element to the transformed constraint matrix */ insist(1 <= i && i <= dsa->m); insist(1 <= j && j <= dsa->n); insist(aij != 0.0); if (dsa->ne == dsa->size) { int *ia = dsa->ia; int *ja = dsa->ja; double *ar = dsa->ar; dsa->size += dsa->size; dsa->ia = ucalloc(1+dsa->size, sizeof(int)); memcpy(&dsa->ia[1], &ia[1], dsa->ne * sizeof(int)); ufree(ia); dsa->ja = ucalloc(1+dsa->size, sizeof(int)); memcpy(&dsa->ja[1], &ja[1], dsa->ne * sizeof(int)); ufree(ja); dsa->ar = ucalloc(1+dsa->size, sizeof(double)); memcpy(&dsa->ar[1], &ar[1], dsa->ne * sizeof(double)); ufree(ar); } insist(dsa->ne < dsa->size); dsa->ne++; dsa->ia[dsa->ne] = i; dsa->ja[dsa->ne] = j; dsa->ar[dsa->ne] = aij; return; }
void id_item_free(id_item_t *item) { item->destructor(item); ufree(item->name); ufree(item); }
/* * Parse the string @a maskStr containing a hex number (with or without * leading "0x") and set nodemask accordingly. * * If the sting is not a valid hex number, each bit in nodemask becomes set. */ static void parseNUMAmask(struct bitmask *nodemask, char *maskStr, int32_t rank) { char *mask, *curchar, *endptr; size_t len; uint32_t curbit; uint16_t i, j, digit; mask = maskStr; if (strncmp(maskStr, "0x", 2) == 0) { /* skip "0x", treat always as hex */ mask += 2; } mask = ustrdup(mask); /* gets destroyed */ len = strlen(mask); curchar = mask + (len - 1); curbit = 0; for (i = len; i > 0; i--) { digit = strtol(curchar, &endptr, 16); if (*endptr != '\0') { mlog("%s: error parsing memory mask '%s'\n", __func__, maskStr); goto error; } for (j = 0; j < 4; j++) { if (digit & (1 << j)) { if ((long int)(curbit + j) > numa_max_node()) { mlog("%s: invalid memory mask entry '%s' for rank %d\n", __func__, maskStr, rank); fprintf(stderr, "Invalid memory mask entry '%s' for rank" " %d\n", maskStr, rank); goto error; } if (numa_bitmask_isbitset(numa_get_mems_allowed(), curbit + j)) { numa_bitmask_setbit(nodemask, curbit + j); } else { mlog("%s: setting bit %u in memory mask not allowed in" " rank %d\n", __func__, curbit + j, rank); fprintf(stderr, "Not allowed to set bit %u in memory mask" " of rank %d\n", curbit + j, rank); } } } curbit += 4; *curchar = '\0'; curchar--; } ufree(mask); return; error: ufree(mask); numa_bitmask_setall(nodemask); }
void CClp_free_warmstart(CClp_warmstart **warm) { /* FREES the memory used by warm. */ if (*warm != NULL) { if ((*warm)->cstat != NULL) ufree((*warm)->cstat), (*warm)->cstat = NULL; if ((*warm)->rstat != NULL) ufree((*warm)->rstat), (*warm)->rstat = NULL; ufree((*warm)), (*warm) = NULL; } return; }
void CClp_free_info(CClp_info **info) { /* FREES the memory used by info. */ if ((*info) != NULL) { if ((*info)->cstat != NULL) ufree((*info)->cstat), (*info)->cstat = NULL; if ((*info)->rstat != NULL) ufree((*info)->rstat), (*info)->rstat = NULL; ufree((*info)), (*info) = NULL; } return; }
/* insert an aligned entry into the table and return non-zero on success */ int __umalloc_aligned_insert(struct mdesc *mdp, void *exact, void *aligned) { umalloc_heap_t *md = (umalloc_heap_t *)mdp; /* fetch a list cell to use */ struct alignlist *newl = mdp->aligned_freelist; if (newl) mdp->aligned_freelist = newl->next; else if ((newl = (struct alignlist *) umalloc(md, sizeof(struct alignlist))) == NULL) return 0; newl->aligned = aligned; newl->exact = exact; if (mdp->aligned_block_table == NULL) { /* first call - create table */ mdp->aligned_block_table = ucalloc(md, INITIAL_TABLE_SZ, sizeof(struct alignlist*)); if (mdp->aligned_block_table == NULL) { ufree(md, newl); return 0; } mdp->aligned_block_tablecnt = 0; mdp->aligned_block_tablesz = INITIAL_TABLE_SZ; } else if (mdp->aligned_block_tablecnt >= mdp->aligned_block_tablesz) { /* rehash */ uintptr_t newtablesz = mdp->aligned_block_tablesz*2 + 1; uintptr_t i; struct alignlist **newtable = ucalloc(md, newtablesz, sizeof(struct alignlist*)); if (newtable == NULL) { ufree(md, newl); return 0; } for (i=0; i < mdp->aligned_block_tablesz; i++) { struct alignlist *cur = mdp->aligned_block_table[i]; while (cur) { struct alignlist *next = cur->next; uintptr_t key = ((uintptr_t)(cur->aligned))%newtablesz; cur->next = newtable[key]; newtable[key] = cur; cur = next; } } { void *oldtable = mdp->aligned_block_table; mdp->aligned_block_table = newtable; mdp->aligned_block_tablesz = newtablesz; ufree(md, oldtable); } } /* insert */ { uintptr_t key = ((uintptr_t)aligned)%mdp->aligned_block_tablesz; newl->next = mdp->aligned_block_table[key]; mdp->aligned_block_table[key] = newl; mdp->aligned_block_tablecnt++; } return 1; }
/* * del_hscprc * * Remove HSC process and all its resources */ void del_hscprc(HSCPRC *hp) { if (hp) { /* remove list */ del_hsctree(hp->defstyle); del_dllist(hp->defent); del_hsctree(hp->deftag); del_dllist(hp->defattr); del_hsctree(hp->deflazy); del_dllist(hp->container_stack); del_dllist(hp->content_stack); del_dllist(hp->inpf_stack); del_dllist(hp->idrefs); del_dllist(hp->select_stack); del_dllist(hp->tag_styles); del_strlist(hp->include_dirs); /* remove precompiled regular expressions */ hscregfreeall(hp->re_uri); /* remove strings */ del_estr(hp->destdir); del_estr(hp->reldir); del_estr(hp->iconbase); del_estr(hp->server_dir); del_estr(hp->if_stack); del_estr(hp->tag_name_str); del_estr(hp->tag_attr_str); del_estr(hp->tag_close_str); del_estr(hp->tmpstr); del_estr(hp->curr_msg); del_estr(hp->curr_ref); del_estr(hp->whtspc); ufreestr(hp->filename_document); ufreestr(hp->strip_tags); ufree(hp->image_buffer); /* remove project-data */ del_project(hp->project); /* close input files */ infclose(hp->inpf); /* remove message arrays */ ufree(hp->msg_ignore); ufree(hp->msg_class); ufree(hp); } }
static void lex_prev_free(void) { switch(lex_prev.token) { case TOKEN_ID: ufree(lex_prev.id); break; case TOKEN_STRING: ufree(lex_prev.string); break; default: break; } }
/*---------------------------------------------------------------------------*/ int xio_free(struct xio_buf **buf) { struct xio_mr *tmr = (*buf)->mr; int retval = 0; if ((*buf)->addr) ufree((*buf)->addr); retval = xio_dereg_mr(&tmr); ufree(*buf); *buf = NULL; return retval; }
/* * del_dlnode() * * remove entry from double linked list * */ void del_dlnode(struct dllist *list, struct dlnode *node) { if (list && node) { /* list & node node defined? */ void (*dd) (APTR) = list->del_data; if (node->data) /* Y-> call destructor */ if (dd) (*dd) (node->data); if (node->prev) /* remove node from list */ node->prev->next = node->next; else list->first = node->next; list->entry_num--; if (node->next) node->next->prev = node->prev; else list->last = node->prev; node->prev = NULL; /* clear node */ node->next = NULL; node->data = NULL; ufree(node); /* free node */ } }
int task_main(void* args) { int i; int eid; int size; int rts; char* ubuf; if (argc < 4) { printf("usage: thr_sender <connect-to> <msg-size> <roundtrips>\n"); return 0; } size = atoi(argv[2]); rts = atoi(argv[3]); BUG_ON((eid = sp_endpoint(SP_REQREP, SP_REQ)) < 0); BUG_ON(sp_connect(eid, argv[1]) < 0); BUG_ON(sp_send(eid, ualloc(size)) != 0); for (i = 0; i < rts; i++) { BUG_ON(sp_send(eid, ualloc(size)) != 0); } BUG_ON(sp_recv(eid, &ubuf) != 0); ufree(ubuf); sp_close(eid); return 0; }
/* * get_mid_estr * * get a part from a expstr; compare BASIC's "MID$()" * * params: dest...destination expstr where to store result part * src....source expstr where to get part from * from...position of char where to begin part (0=first char) * num....number of chars to get * result: TRUE and result in dest if ok; else FALSE is returned an * dest is left untouched * * NOTE: it is possible to use the source-exstr as destination-expstr, * because the result is copied to a temp. expstr before * ( example: get_mid_estr( hugo, hugo, 3, 4 ); ) */ BOOL get_mid_estr(EXPSTR * dest, EXPSTR * src, size_t from, size_t num) { BOOL ok = FALSE; EXPSTR *tmp = init_estr(dest->es_step); if (tmp) { STRPTR old_data = tmp->es_data; /* check size */ if (from >= src->es_len) from = src->es_len - 1; if (from + num >= src->es_len) num = src->es_len - from - 1; /* set new mem for tmp */ ok = set_estr_mem(tmp, modadj(num + 1, tmp->es_step)); if (ok) { /* copy data */ strncpy(estr2str(tmp), estr2str(src) + from, num); tmp->es_data[num] = 0; tmp->es_len = num + 1; ufree(old_data); ok = estrcpy(dest, tmp); } del_estr(tmp); } return (ok); }
void id_item_default_release(id_item_t *item) { assert(item != NULL); switch (item->type) { case ID_VAR: if (item->var != NULL) { var_clear(item->var); ufree(item->var); item->var = NULL; } break; case ID_ARR: if (item->arr != NULL) { arr_free(item->arr); item->arr = NULL; } break; case ID_UNKNOWN: default: error(1, "unknown id type\n"); break; } }
/* **------------------------------------- ** append char/string to expstr **------------------------------------- */ BOOL app_estrch( EXPSTR *es, int ch ) { BOOL ok = TRUE; STRPTR s; if ( es->es_len >= es->es_size ) { /* enough mem left? */ STRPTR old_data = es->es_data; /* N->remeber old data ptr */ if ( set_estr_mem(es, es->es_size + es->es_step ) ) { /* set new mem sucessful? */ strcpy( es->es_data, /* Y->copy old data */ old_data ); ufree( old_data ); /* release old data */ } else { /* N->return error */ ok = FALSE; } } if ( ok ) { s = es->es_data; s[es->es_len-1] = ch; /* append new char to expstr */ s[es->es_len] = 0; es->es_len++; /* incr. expstr length */ } return( ok ); }
/* * del_hsctag */ void del_hsctag(APTR data) { HSCTAG *tag = (HSCTAG *) data; /* release mem */ ufreestr(tag->name); ufreestr(tag->name); del_estr(tag->op_text); del_estr(tag->cl_text); ufreestr(tag->mbi); ufreestr(tag->naw); del_dllist(tag->attr); del_infilepos(tag->start_fpos); del_infilepos(tag->end_fpos); /* clear values */ tag->option = 0; tag->op_text = NULL; tag->cl_text = NULL; tag->attr = NULL; tag->uri_size = NULL; tag->uri_stripext = NULL; ufree(tag); }
BOOL ugly_dbg_app_estrch(EXPSTR * es, int ch, STRPTR file, ULONG line) { BOOL ok = TRUE; if (!es) { es_null("app_estrch", file, line); ok = FALSE; } else if (es->es_len >= es->es_size) { /* enough mem left? */ STRPTR old_data = es->es_data; /* N->remeber old data ptr */ if (ugly_dbg_set_estr_mem(es, es->es_size + es->es_step, file, line)) { /* set new mem sucessfully? */ strcpy(es->es_data, /* Y->copy old data */ old_data); ufree(old_data); /* release old data */ } else { /* N->return error */ ok = FALSE; } } if (ok) { STRPTR s; s = es->es_data; s[es->es_len - 1] = ch; /* append new char to expstr */ s[es->es_len] = 0; es->es_len++; /* incr. expstr length */ } return (ok); }
//------------------------------------------------------------------- void conf_save() { static const long t=CONF_MAGICK_VALUE; register int i; int fd; char *buf=umalloc(sizeof(t)+CONF_NUM*(sizeof(conf_info[0].id)+sizeof(conf_info[0].size))+sizeof(conf)); char *p=buf; fd = open(CONF_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0777); if (fd>=0){ memcpy(p, &t, sizeof(t)); p+=sizeof(t); for (i=0; i<CONF_NUM; ++i) { memcpy(p, &(conf_info[i].id), sizeof(conf_info[i].id)); p+=sizeof(conf_info[i].id); memcpy(p, &(conf_info[i].size), sizeof(conf_info[i].size)); p+=sizeof(conf_info[i].size); memcpy(p, conf_info[i].var, conf_info[i].size); p+=conf_info[i].size; } write(fd, buf, p-buf); close(fd); } ufree(buf); }
/** * Free pixel buffer * * @v refcnt Reference count */ static void free_pixbuf ( struct refcnt *refcnt ) { struct pixel_buffer *pixbuf = container_of ( refcnt, struct pixel_buffer, refcnt ); ufree ( pixbuf->data ); free ( pixbuf ); }
static void check_memory(void) { param_list_t *p_list; int n_allocated; if (Nparams + 1 > Nallocated) { /* * allocate another block of space */ n_allocated = Nallocated + N_ALLOCATE; p_list = (param_list_t *) umalloc(n_allocated * sizeof(param_list_t)); if (Nallocated > 0) { memcpy(p_list, Plist, Nallocated * sizeof(param_list_t)); ufree(Plist); } /* if (Nallocated > 0) */ Plist = p_list; Nallocated = n_allocated; } /* if (Nparams + 1 > Nallocated) */ }
/* * free_args * * free all memory allocated by _prepare_args() * * MUST be called after _set_args() * */ void free_args(struct arglist *al) { if (al) { del_dllist(al->al_list); ufree(al); } }
int dispose_stack(stack* s, void (*ufree)(void*)) { void* data; while ((data = pop_stack(s)) != NULL) { ufree(data); } free(s); return 1; }
/* del_idref: remove referenced id */ VOID del_idref(APTR data) { IDREF *idref = (IDREF *) data; ufreestr(idref->name); del_infilepos(idref->fpos); ufree(idref); }
/* ** del_tag */ void del_tag( APTR data ) { HSCTAG *tag = (HSCTAG *)data; ufreestr( tag->name ); ufree( tag ); }
/* * del_hscprc * * remove hsc process and all it's resources */ VOID del_hscprc(HSCPRC * hp) { if (hp) { /* remove list */ del_dllist(hp->defent); del_dllist(hp->deftag); del_dllist(hp->defattr); del_dllist(hp->container_stack); del_dllist(hp->content_stack); del_dllist(hp->inpf_stack); del_dllist(hp->idrefs); del_dllist(hp->select_stack); del_strlist(hp->include_dirs); /* remove strings */ del_estr(hp->destdir); del_estr(hp->reldir); del_estr(hp->iconbase); del_estr(hp->server_dir); del_estr(hp->if_stack); del_estr(hp->tag_name_str); del_estr(hp->tag_attr_str); del_estr(hp->tag_close_str); del_estr(hp->tmpstr); del_estr(hp->curr_msg); del_estr(hp->curr_ref); del_estr(hp->whtspc); ufreestr(hp->filename_document); ufreestr(hp->strip_tags); /* remove project-data */ del_project(hp->project); /* close input files */ infclose(hp->inpf); /* remove message arrays */ ufree(hp->msg_ignore); ufree(hp->msg_class); ufree(hp); } }
void b_close(int fd) { if (fd >= 0) close(fd); if (buf_load) ufree(buf_load); buf_load=0; }