double *dist_ps(Point *pt, LSEG *lseg) { double m; /* slope of perp. */ LINE *ln; double *result, *tmpdist; Point *ip; /* construct a line that's perpendicular. See if the intersection of the two lines is on the line segment. */ if (lseg->p[1].x == lseg->p[0].x) m = 0; else if (lseg->p[1].y == lseg->p[0].y) /* slope is infinite */ m = (double)DBL_MAX; else m = (-1) * (lseg->p[1].y - lseg->p[0].y) / (lseg->p[1].x - lseg->p[0].x); ln = line_construct_pm(pt, m); if ((ip = interpt_sl(lseg, ln)) != NULL) result = point_distance(pt, ip); else /* intersection is not on line segment, so distance is min of distance from point to an endpoint */ { result = point_distance(pt, &lseg->p[0]); tmpdist = point_distance(pt, &lseg->p[1]); if (*tmpdist < *result) *result = *tmpdist; PFREE (tmpdist); } if (ip != NULL) PFREE(ip); PFREE(ln); return (result); }
static void free_event(kherr_event * e) { EnterCriticalSection(&cs_error); assert(IS_KHERR_EVENT(e)); #ifdef DEBUG assert(LNEXT(e) == NULL); assert(LPREV(e) == NULL); #endif if(e->flags & KHERR_RF_FREE_SHORT_DESC) { assert(e->short_desc); PFREE((void *) e->short_desc); } if(e->flags & KHERR_RF_FREE_LONG_DESC) { assert(e->long_desc); PFREE((void *) e->long_desc); } if(e->flags & KHERR_RF_FREE_SUGGEST) { assert(e->suggestion); PFREE((void *) e->suggestion); } free_event_params(e); ZeroMemory(e, sizeof(*e)); LPUSH(&evt_free_list, e); LeaveCriticalSection(&cs_error); }
static void free_event_params(kherr_event * e) { assert(IS_KHERR_EVENT(e)); if(parm_type(e->p1) == KEPT_STRINGT) { assert((void *) parm_data(e->p1)); PFREE((void*) parm_data(e->p1)); } ZeroMemory(&e->p1, sizeof(e->p1)); if(parm_type(e->p2) == KEPT_STRINGT) { assert((void *) parm_data(e->p2)); PFREE((void*) parm_data(e->p2)); } ZeroMemory(&e->p2, sizeof(e->p2)); if(parm_type(e->p3) == KEPT_STRINGT) { assert((void *) parm_data(e->p3)); PFREE((void*) parm_data(e->p3)); } ZeroMemory(&e->p3, sizeof(e->p3)); if(parm_type(e->p4) == KEPT_STRINGT) { assert((void *) parm_data(e->p4)); PFREE((void*) parm_data(e->p4)); } ZeroMemory(&e->p4, sizeof(e->p4)); }
/* called with cs_mkq_global && cs_kmq_types held */ void kmqint_free_msg_type(int t) { kmq_msg_type * pt; kmq_msg_subscription * s; pt = msg_types[t]; msg_types[t] = NULL; if (pt == NULL) return; /* all the subscriptions attached to a message type are owned by the message type */ LPOP(&pt->subs, &s); while(s) { s->magic = 0; PFREE(s); LPOP(&pt->subs, &s); } pt->completion_handler = NULL; LDELETE(&all_msg_types, pt); PFREE(pt); }
/* Called with cs_credtype held */ void kcdb_credtype_check_and_delete(khm_int32 id) { kcdb_credtype_i * ict; #ifdef DEBUG assert(id >= 1 && id <= KCDB_CREDTYPE_MAX_ID); #endif if (id < 1 || id > KCDB_CREDTYPE_MAX_ID) return; ict = kcdb_credtype_tbl[id]; if(!ict) return; if((ict->flags & KCDB_CTI_FLAG_DELETED) && !ict->refcount) { kcdb_credtype_tbl[id] = NULL; LDELETE(&kcdb_credtypes, ict); PFREE(ict->ct.name); if(ict->ct.short_desc) PFREE(ict->ct.short_desc); if(ict->ct.long_desc) PFREE(ict->ct.long_desc); if(ict->ct.sub) kmq_delete_subscription(ict->ct.sub); PFREE(ict); } }
/* lseg_distance - * If two segments don't intersect, then the closest * point will be from one of the endpoints to the other * segment. */ double *lseg_distance(LSEG *l1, LSEG *l2) { double *d, *result; result = PALLOCTYPE(double); if (lseg_intersect(l1, l2)) { *result = 0.0; return(result); } *result = (double)DBL_MAX; d = dist_ps(&l1->p[0], l2); *result = Min(*result, *d); PFREE(d); d = dist_ps(&l1->p[1], l2); *result = Min(*result, *d); PFREE(d); d = dist_ps(&l2->p[0], l1); *result = Min(*result, *d); PFREE(d); d = dist_ps(&l2->p[1], l1); *result = Min(*result, *d); PFREE(d); return(result); }
KHMEXP BOOL KHMAPI khui_delete_ilist(khui_ilist * il) { DeleteObject(il->img); DeleteObject(il->mask); PFREE(il->idlist); PFREE(il); return TRUE; }
void mrl_properties_video_free (mrl_properties_video_t *video) { if (!video) return; PFREE (video->codec); PFREE (video); }
void mrl_properties_audio_free (mrl_properties_audio_t *audio) { if (!audio) return; PFREE (audio->codec); PFREE (audio); }
SDB_IPI Rangstr json_find (const char *s, Rangstr *rs) { #define RESFIXSZ 1024 RangstrType resfix[RESFIXSZ] = {0}; RangstrType *res = resfix; int i, j, n, len, ret; Rangstr rsn; if (!s) { return rangstr_null (); } len = strlen (s); if (len > RESFIXSZ) { res = calloc (len + 1, sizeof (RangstrType)); if (!res) { eprintf ("Cannot allocate %d byte(s)\n", len + 1); return rangstr_null (); } } ret = js0n ((const unsigned char *)s, len, res); #define PFREE(x) if (x && x != resfix) free (x) if (ret > 0) { PFREE (res); return rangstr_null (); } if (*s == '[') { n = rangstr_int (rs); if (n < 0) { goto beach; } for (i = j = 0; res[i] && j < n; i += 2, j++); if (!res[i]) { goto beach; } rsn = rangstr_news (s, res, i); PFREE (res); return rsn; } else { for (i=0; res[i]; i+=4) { Rangstr rsn = rangstr_news (s, res, i); if (!rangstr_cmp (rs, &rsn)) { rsn = rangstr_news (s, res, i+2); PFREE (res); return rsn; } } } beach: PFREE (res); return rangstr_null (); }
static void mrl_resource_videodisc_free (mrl_resource_videodisc_args_t *args) { if (!args) return; PFREE (args->device); PFREE (args->audio_lang); PFREE (args->sub_lang); }
static void mrl_resource_network_free (mrl_resource_network_args_t *args) { if (!args) return; PFREE (args->url); PFREE (args->username); PFREE (args->password); PFREE (args->user_agent); }
void pl_playlist_free (playlist_t *playlist) { if (!playlist) return; if (playlist->mrl_list) mrl_list_free (playlist->mrl_list); PFREE (playlist->shuffle_list); PFREE (playlist); }
static void mrl_resource_tv_free (mrl_resource_tv_args_t *args) { if (!args) return; PFREE (args->device); PFREE (args->driver); PFREE (args->channel); PFREE (args->output_format); PFREE (args->norm); }
/* called with cs_identpro held */ static void identpro_check_and_set_default_provider(void) { wchar_t * p_order = NULL; khm_size cb; khm_handle csp_kcdb = NULL; khm_int32 rv; kcdb_identpro_i * p = NULL; wchar_t * e; if (KHM_SUCCEEDED(khc_open_space(NULL, L"KCDB", KHM_PERM_READ, &csp_kcdb))) { rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", NULL, &cb); if (rv == KHM_ERROR_TOO_LONG && cb > sizeof(wchar_t) * 2) { p_order = PMALLOC(cb); rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", p_order, &cb); if (KHM_FAILED(rv)) { PFREE(p_order); p_order = NULL; } } khc_close_space(csp_kcdb); csp_kcdb = NULL; } for (e = p_order; e && e[0]; e = multi_string_next(e)) { p = identpro_find_by_name(e); if (p) break; } if (p != NULL) { if (DEFAULT_PROVIDER != p) { QDEL(&id_providers, p); QPUSH(&id_providers, p); #ifdef DEBUG assert(DEFAULT_PROVIDER == p); #endif kcdbint_identpro_post_message(KCDB_OP_NEW_DEFAULT, DEFAULT_PROVIDER); } } if (p) identpro_release(p); if (p_order) PFREE(p_order); }
static void mrl_metadata_audio_free (mrl_metadata_audio_t *audio) { mrl_metadata_audio_t *audio_n; while (audio) { PFREE (audio->name); PFREE (audio->lang); audio_n = audio->next; PFREE (audio); audio = audio_n; } }
void kcdb_buf_delete(kcdb_buf * buf) { buf->cb_buffer = 0; buf->cb_used = 0; if(buf->buffer) PFREE(buf->buffer); buf->buffer = NULL; buf->n_fields = 0; buf->nc_fields = 0; if(buf->fields) PFREE(buf->fields); buf->fields = NULL; }
/* box_dt - returns the distance between the * center points of two boxes. */ double box_dt(BOX *box1, BOX *box2) { double result; Point *box_center(), *a, *b; a = box_center(box1); b = box_center(box2); result = HYPOT(a->x - b->x, a->y - b->y); PFREE(a); PFREE(b); return(result); }
static void mrl_metadata_sub_free (mrl_metadata_sub_t *sub) { mrl_metadata_sub_t *sub_n; while (sub) { PFREE (sub->name); PFREE (sub->lang); sub_n = sub->next; PFREE (sub); sub = sub_n; } }
/* box_distance - returns the distance between the * center points of two boxes. */ double *box_distance(BOX *box1, BOX *box2) { double *result; Point *box_center(), *a, *b; result = PALLOCTYPE(double); a = box_center(box1); b = box_center(box2); *result = HYPOT(a->x - b->x, a->y - b->y); PFREE(a); PFREE(b); return(result); }
/* ** Distance from a point to a path */ double *dist_ppth(Point *pt, PATH *path) { double *result; double *tmp; int i; LSEG lseg; switch (path->npts) { case 0: result = PALLOCTYPE(double); *result = Abs((double) DBL_MAX); /* +infinity */ break; case 1: result = point_distance(pt, &path->p[0]); break; default: /* * the distance from a point to a path is the smallest distance * from the point to any of its constituent segments. */ Assert(path->npts > 1); result = PALLOCTYPE(double); for (i = 0; i < path->npts - 1; ++i) { statlseg_construct(&lseg, &path->p[i], &path->p[i+1]); tmp = dist_ps(pt, &lseg); if (i == 0 || *tmp < *result) *result = *tmp; PFREE(tmp); } break; } return(result); }
void conn_pool_free(conn_pool_t* pool) { conn_cb_t* cbs = pool->cbs; int i; for(i=0;i<pool->size; i++){ if(pool->conns[i] != NULL){ free_and_close(pool->conns[i], cbs,&pool->statis); pool->conns[i] = NULL; sync_dec(&pool->curconns); } } pthread_spin_destroy(&pool->spin); PFREE(pool->cbs); PFREE(pool->conns); PFREE(pool); }
/* ** find intersection of the two lines, and see if it falls on ** both segments. */ long lseg_intersect(LSEG *l1, LSEG *l2) { LINE *ln; Point *interpt; long retval; ln = line_construct_pp(&l2->p[0], &l2->p[1]); interpt = interpt_sl(l1, ln); if (interpt != NULL && on_ps(interpt, l2)) /* interpt on l1 and l2 */ retval = 1; else retval = 0; if (interpt != NULL) PFREE(interpt); PFREE(ln); return(retval); }
/* called on an unreleased credset, or with credset::cs held */ void kcdb_credset_buf_delete(kcdb_credset * cs) { PFREE(cs->clist); cs->nc_clist = 0; cs->nclist = 0; }
KHMEXP khm_int32 KHMAPI kcdb_credset_delete(khm_handle vcredset) { kcdb_credset * cs; int i; if(!kcdb_credset_is_credset(vcredset)) { return KHM_ERROR_INVALID_PARAM; } cs = (kcdb_credset *) vcredset; EnterCriticalSection(&cs_credset); LDELETE(&kcdb_credsets, cs); LeaveCriticalSection(&cs_credset); EnterCriticalSection(&(cs->cs)); cs->magic = 0; for(i=0;i<cs->nclist;i++) { if(cs->clist[i].cred) { kcdb_cred_release((khm_handle) cs->clist[i].cred); } } kcdb_credset_buf_delete(cs); LeaveCriticalSection(&(cs->cs)); DeleteCriticalSection(&(cs->cs)); PFREE(cs); return KHM_ERROR_SUCCESS; }
void k5_read_file_cc_data(k5_ccc_data * d) { khm_int32 t; wchar_t * fclist = NULL; wchar_t * fc; khm_size cb; #ifdef DEBUG assert(csp_params); #endif d->inc_api = TRUE; t = TRUE; khc_read_int32(csp_params, L"MsLsaList", &t); d->inc_mslsa = t; if (khc_read_multi_string(csp_params, L"FileCCList", NULL, &cb) != KHM_ERROR_TOO_LONG || cb <= sizeof(wchar_t) * 2) { k5_flush_file_ccs(d); } else { fclist = PMALLOC(cb); #ifdef DEBUG assert(fclist); #endif khc_read_multi_string(csp_params, L"FileCCList", fclist, &cb); for(fc = fclist; fc && *fc; fc = multi_string_next(fc)) { k5_add_file_cc(d, fc); } PFREE(fclist); } }
KHMEXP khm_int32 KHMAPI khui_alert_set_title(khui_alert * alert, const wchar_t * title) { size_t cb = 0; assert(alert->magic == KHUI_ALERT_MAGIC); if(title) { if(FAILED(StringCbLength(title, KHUI_MAXCB_TITLE, &cb))) { return KHM_ERROR_INVALID_PARAM; } cb += sizeof(wchar_t); } EnterCriticalSection(&cs_alerts); if(alert->title && (alert->flags & KHUI_ALERT_FLAG_FREE_TITLE)) { PFREE(alert->title); alert->title = NULL; alert->flags &= ~KHUI_ALERT_FLAG_FREE_TITLE; } if(title) { alert->title = PMALLOC(cb); StringCbCopy(alert->title, cb, title); alert->flags |= KHUI_ALERT_FLAG_FREE_TITLE; } alert->flags |= KHUI_ALERT_FLAG_MODIFIED; LeaveCriticalSection(&cs_alerts); return KHM_ERROR_SUCCESS; }
static void mrl_resource_cd_free (mrl_resource_cd_args_t *args) { if (!args) return; PFREE (args->device); }
/*! \internal \brief Unsubscribes a window from a message type \note Obtains ::cs_kmq_types */ KHMEXP khm_int32 KHMAPI kmq_unsubscribe_hwnd(khm_int32 type, HWND hwnd) { kmq_msg_subscription * s; s = kmqint_msg_type_del_sub_hwnd(type, hwnd); if(s) PFREE(s); return (s)?KHM_ERROR_SUCCESS:KHM_ERROR_NOT_FOUND; }
void kcdb_type_exit(void) { EnterCriticalSection(&cs_type); PFREE(kcdb_type_tbl); /*TODO: free up the individual types */ LeaveCriticalSection(&cs_type); DeleteCriticalSection(&cs_type); }