int DropVariable(Variable *vp) { int i; Variable v = *vp; VariableDeleteItems(v); cl_free(v->my_name); cl_free(v->my_corpus); cl_free(v->my_attribute); for (i = 0; i < nr_variables; i++) if (VariableSpace[i] == v) { VariableSpace[i] = NULL; break; } if (i >= nr_variables) { fprintf(stderr, "Error #5 in variable logic. Please contact developer.\n"); } *vp = NULL; vp = NULL; return 1; }
/* Parses world and inits possible positions. */ cop_knowledge_t *cl_init (FILE *file) { cop_knowledge_t *c; node_line_t *startnode; c = malloc (sizeof (*c)); if (!c) return NULL; bzero (c, sizeof (*c)); c->world = parse_world_skeleton (file); c->map = build_map (c->world); if (!c->map) { cl_free (c); return NULL; } c->prpsize = (c->map->num_nodes - 1) / (sizeof (int)*8) + 1; if (!new_turn (c)) { cl_free (c); return NULL; } startnode = node_by_loc (c->map, ROBBER_START_POS); if (!startnode) { dprintf ("ALERT: Start pos is not on map!!\n"); exit (1); } set_prp (c, startnode->index); c->prp_cnt[c->turn-1] = 1; return c; }
/** * Delete a Component object. * * The specified component object, and all memory associated with it, is freed. * * @return Always 1. */ int comp_drop_component(Component *comp) { assert((comp != NULL) && "NULL component passed to attributes:comp_drop_component"); assert(comp->attribute); if (comp->attribute->any.components[comp->id] != comp) assert(0 && "comp is not member of that attr"); comp->attribute->any.components[comp->id] = NULL; if (comp->id == CompHuffCodes) { /* it may be empty, since declare_component doesn't yet load the * data */ cl_free(comp->attribute->pos.hc); } mfree(&(comp->data)); cl_free(comp->path); comp->corpus = NULL; comp->attribute = NULL; comp->id = CompLast; free(comp); return 1; }
void LogToCircularBuffer(CircularBuffer_t *buffer, int level, const char *fmt, ...) { va_list ap; char buf[MAXLINE]; int nbytes; CircularBufferEntry_t *entry = cl_malloc(sizeof(CircularBufferEntry_t)); if (!entry) { return; } va_start(ap, fmt); nbytes=vsnprintf(buf, MAXLINE, fmt, ap); /* nbytes=vasprintf(&buf, fmt, ap); */ va_end(ap); entry->buf = buf; entry->level = level; g_queue_push_tail(buffer->queue, entry); while(buffer->queue->length > buffer->size) { entry = g_queue_pop_head(buffer->queue); cl_free(entry->buf); cl_free(entry); } }
void cl_delete_kernel_bin(cl_kernel_bin_t *bins) { if (bins) { cl_uint i = 0; if (bins->data) { for (i = 0; i < bins->numDevices; i++) { if (bins->data[i]) { cl_free(bins->data[i]); bins->data[i] = NULL; } } cl_free(bins->data); bins->data = NULL; } if (bins->sizes) { cl_free(bins->sizes); bins->sizes = NULL; } // @TODO Fill in the structure with a bunch of garbage which will cause an abort later if dereferenced. //memset(bins, 0xFE, sizeof(cl_kernel_bin_t)); cl_free(bins); } }
int cloudvpn_scheduler_run (int* keep_running) { struct work_queue*p; struct work*w; while (*keep_running) { cl_mutex_lock (queue_mutex); if (!queue) { /* just wait for the signal and retry */ cl_cond_wait (queue_just_filled, queue_mutex); cl_mutex_unlock (queue_mutex); } else { p = queue; queue = queue->next; cl_mutex_unlock (queue_mutex); w = p->w; cl_free (p); do_work (w); /* don't delete statically assigned work */ if (! (w->is_static) ) cl_free (w); } } return 0; }
/** * Frees all the memory used within a matchlist, and re-initialises all its variables */ void free_matchlist(Matchlist *matchlist) { cl_free(matchlist->start); cl_free(matchlist->end); cl_free(matchlist->target_positions); init_matchlist(matchlist); }
/** check variable's strings against corpus.attribute lexicon */ int VerifyVariable(Variable v, Corpus *corpus, Attribute *attribute) { int i; int nr_valid, nr_invalid; if (v->valid == 0 || v->my_corpus == NULL || v->my_attribute == NULL || strcmp(v->my_corpus, corpus->registry_name) != 0 || strcmp(v->my_attribute, attribute->any.name) != 0) { v->valid = 0; cl_free(v->my_corpus); cl_free(v->my_attribute); if (attribute->any.type != ATT_POS) { return 0; } v->my_corpus = cl_strdup(corpus->registry_name); v->my_attribute = cl_strdup(attribute->any.name); nr_valid = 0; nr_invalid = 0; for (i = 0; i < v->nr_items; i++) { if (!v->items[i].free) { if (v->items[i].sval == NULL) { fprintf(stderr, "Error #1 in variable logic. Contact developer.\n"); v->items[i].ival = -1; } else v->items[i].ival = get_id_of_string(attribute, v->items[i].sval); if (v->items[i].ival < 0) nr_invalid++; else nr_valid++; } } v->nr_valid_items = nr_valid; v->nr_invalid_items = nr_invalid; if (nr_valid > 0) v->valid = 1; else v->valid = 0; } return v->valid; }
void EmptyCircularBuffer(CircularBuffer_t *buffer) { CircularBufferEntry_t *entry = NULL; while(buffer->queue->length > 0) { entry = g_queue_pop_head(buffer->queue); cl_free(entry->buf); cl_free(entry); } }
void LoadFontData() { int size; char *lpMemory; size = readFile->ReadPackFile(pack_gparts,"mainFont.fnt",(char **)&lpMemory); CopyMemory(fontMain,lpMemory,size); cl_free(lpMemory); size = readFile->ReadPackFile(pack_gparts,"systemFont.fnt",(char **)&lpMemory); CopyMemory(fontSystem,lpMemory,size); cl_free(lpMemory); } // LoadFontData
/** * Deletes a SingleMapping object. * * @param smap Address of the object to delete. * @return Always 1. */ int drop_single_mapping(SingleMapping *smap) { cl_free((*smap)->class_name); cl_free((*smap)->tokens); free(*smap); *smap = NULL; return 1; }
int main(int argc, char *argv[]) { const cl_uint numBodies = 10; float *m = cl_malloc_array(float, numBodies); float *t = cl_malloc_array(float, numBodies); cl_float4 *a = cl_malloc_array(cl_float4, numBodies); cl_float4 *v = cl_malloc_array(cl_float4, numBodies); cl_float4 *p = cl_malloc_array(cl_float4, numBodies); #ifdef CL_BUILD_RUNTIME cl_uint type = clGetTypeFromString(CL_USER_DEVICE_TYPE); cl_uint count = CL_USER_DEVICE_COUNT; cl_environment_t *pEnv = clCreateEnvironment(KDIR"kernel_nbody.cl",type,count,notify,CL_ARGS); #else cl_environment_t *pEnv = clCreateEnvironmentFromBins(&gKernelBins, notify, CL_ARGS); #endif if (pEnv) { cl_uint i = 0, j = 0; cl_uint numIterations = (argc > 1?atoi(argv[1]):10); for (i = 0; i < numBodies; i++) { m[i] = frand() * ipow(10,rrand(4,27)); // masses should be 10^4 - 10^27 ("Earth heavy") frand4(a[i], 1, 3); frand4(v[i], 1, 2); frand4(p[i], 4, 8); t[i] = 0.001f; // 1 millisecond. } i = 0; for (j = 0; j < numIterations; j++) { nbodies(pEnv, m, a, v, p, t, numBodies); #if defined(DARWIN) printf("[%6u] p={%lf,%lf,%lf} v={%lf,%lf,%lf} a={%lf,%lf,%lf}\n", i, p[i][0], p[i][1], p[i][2], v[i][0], v[i][1], v[i][2], a[i][0], a[i][1], a[i][2]); #else printf("[%6u] p={%lf,%lf,%lf} v={%lf,%lf,%lf} a={%lf,%lf,%lf}\n", i, p[i].s[0], p[i].s[1], p[i].s[2], v[i].s[0], v[i].s[1], v[i].s[2], a[i].s[0], a[i].s[1], a[i].s[2]); #endif } clDeleteEnvironment(pEnv); cl_free(t); cl_free(m); cl_free(v); cl_free(a); cl_free(p); } return 0; }
gboolean DumpCircularBuffer(int nsig, gpointer user_data) { CircularBuffer_t *buffer = user_data; CircularBufferEntry_t *entry = NULL; if(buffer == NULL) { /* error */ cl_log(LOG_ERR, "No buffer supplied to dump."); return FALSE; } if(logging_daemon_chan != NULL && logging_daemon_chan->send_queue->max_qlen < buffer->size) { /* We have no hope of getting the whole buffer out via the * logging daemon. Use direct log instead so the messages * come out in the right order. */ cl_log_depth++; } cl_log(LOG_INFO, "Mark: Begin dump of buffer %s", buffer->name); if(buffer->empty_after_dump) { while(buffer->queue->length > 0) { entry = g_queue_pop_head(buffer->queue); cl_log(entry->level, "%s", entry->buf); cl_free(entry->buf); cl_free(entry); } } else { #if 1 cl_log(LOG_ERR, "This requires g_queue_peek_nth() from glib 2.4"); #else uint lpc = 0; uint queue_len = buffer->queue->length; for(lpc = 0; lpc < queue_len; lpc++) { entry = g_queue_peek_nth(buffer->queue, lpc); cl_log(entry->level, "%s", entry->buf); } #endif } if(logging_daemon_chan != NULL && logging_daemon_chan->send_queue->max_qlen < buffer->size) { /* Return is back to normal */ cl_log_depth--; } cl_log(LOG_INFO, "Mark: End dump of buffer %s", buffer->name); return TRUE; }
int cloudvpn_scheduler_destroy() { struct work_queue*p; while (queue) { p = queue; queue = queue->next; cl_free (p->w); cl_free (p); } return cl_mutex_destroy (queue_mutex) || cl_cond_destroy (queue_just_filled); }
/** free global list of tabulation items (before building new one) */ void free_tabulation_list(void) { TabulationItem item = TabulationList; TabulationItem old = NULL; while (item) { cl_free(item->attribute_name); /* if we had proper reference counting, we would delete the attribute handle here (but calling cl_delete_attribute() would _completely_ remove the attribute from the corpus for this session!) */ old = item; item = item->next; cl_free(old); } TabulationList = NULL; }
/** * Deletes a Mapping object. * * @param map Address of the object to delete. * @return Always 1. */ int drop_mapping(Mapping *map) { (*map)->corpus = NULL; (*map)->attribute = NULL; cl_free((*map)->mapping_name); cl_free((*map)->classes); free(*map); *map = NULL; return 1; }
/** * Parses an input line into cwb-s-encode. * * Usage: * * ok = sencode_parse_line(char *line, int *start, int *end, char **annot); * * Expects standard TAB-separated format; first two fields must be numbers, * optional third field is returned in annot - if not present, annot is * set to NULL. * * @param line The line to be parsed. * @param start Location for the start cpos. * @param end Location for the end cos. * @param annot Location for the annotation string. * @return Boolean; true for all OK, false for error. */ int sencode_parse_line(char *line, int *start, int *end, char **annot) { char *field, *field_end; char *line_copy = cl_strdup(line); /* work on copy to retain original for error messages */ int has_annotation = 1; /* first field: INT range_start */ field = line_copy; field_end = strchr(field, '\t'); if (field_end == NULL) return 0; else { *field_end = 0; errno = 0; *start = atoi(field); if (errno != 0 || *start < 0) return 0; field = field_end + 1; } /* second field: INT range_end */ field_end = strchr(field, '\t'); if (field_end == NULL) { has_annotation = 0; field_end = strchr(field, '\n'); } if (field_end == NULL) return 0; else { *field_end = 0; errno = 0; *end = atoi(field); if (errno != 0 || *end < 0) return 0; field = field_end + 1; } /* optional third field: STRING annotation */ if (has_annotation) { field_end = strchr(field, '\t'); if (field_end != NULL) { return 0; /* make sure there are no extra fields */ } else { field_end = strchr(field, '\n'); if (field_end == NULL) { return 0; } else { *field_end = 0; *annot = cl_strdup(field); } } } else { *annot = NULL; } cl_free(line_copy); return 1; /* OK */ }
void cl_log_args(int argc, char **argv) { int lpc = 0; int len = 0; int existing_len = 0; char *arg_string = NULL; if(argc == 0 || argv == NULL) { return; } for(;lpc < argc; lpc++) { if(argv[lpc] == NULL) { break; } len = 2 + strlen(argv[lpc]); /* +1 space, +1 EOS */ if(arg_string) { existing_len = strlen(arg_string); } arg_string = cl_realloc(arg_string, len + existing_len); sprintf(arg_string + existing_len, "%s ", argv[lpc]); } cl_log(LOG_INFO, "Invoked: %s", arg_string); cl_free(arg_string); }
static int uncompress2compress(struct ha_msg* msg, int index) { char* buf; size_t buflen = MAXMSG; int rc = HA_FAIL; buf = cl_malloc(buflen); if (!buf) { cl_log(LOG_ERR, "%s: failed to allocate buffer", __FUNCTION__); goto err; } if (msg->types[index] != FT_UNCOMPRESS){ cl_log(LOG_ERR, "%s: the %dth field is not FT_UNCOMPRESS type", __FUNCTION__, index); goto err; } if (cl_compress_field(msg, index, buf, &buflen) != HA_OK){ cl_log(LOG_ERR, "%s: compressing %dth field failed", __FUNCTION__, index); goto err; } rc = cl_msg_replace(msg, index, buf, buflen, FT_COMPRESS); err: if (buf) { cl_free(buf); } return rc; }
/** * Creates, and opens for text-mode write, a temporary file. * * Temporary files have the prefix "$PID.cqpt." (where $PID = the process ID of this copy of CQP) * and are placed in the directory defined as TEMPDIR_PATH. * * @see TEMPDIR_PATH * @see TEMP_FILENAME_BUFSIZE * @param tmp_nam_buffer A pre-allocated buffer which will be overwritten * with the name of the temporary file. This should be at least * TEMP_FILENAME_BUFSIZE bytes in size. If opening is unsuccessful, * this will be set to "". * @return A stream (FILE *) to the opened temporary file, or NULL * if unsuccessful. */ FILE * open_temporary_file(char *tmp_name_buffer) { char *intermed_buffer; FILE *fd = NULL; assert((tmp_name_buffer != NULL) && "Invalid NULL argument in open_temporary_file()."); /* note there is a potential problem using tempnam rather than tmpfile () or mkstemp () if there * is more than one copy of cqp running and they both call this function at the same time. * A race condition could result where copy#2 gets the same name as copy#1 by calling tempnam() * after copy#1 calls it but before copy#1 opens the file. * * For this reason, the process ID is used to make the filename unique to this process. * But we then need to try to open the file for read to check whether it exists (because * tempnam() doesn't guarantee that the filename will still not exist once we add an * arbitrary numerical prefix!) */ do { if (fd) fclose(fd); intermed_buffer = tempnam(TEMPDIR_PATH, "cqpt."); /* we need to catch the pointer in order to free it below */ sprintf(tmp_name_buffer, "%d.%s", (int)getpid(), intermed_buffer); cl_free(intermed_buffer); } while (NULL != (fd = fopen(tmp_name_buffer, "r"))); fd = fopen(tmp_name_buffer, "w"); if (fd) return fd; else { perror("open_temporary_file(): can't create temporary file"); return NULL; } }
static int string2struct(void* value, size_t vallen, int depth, void** nv, size_t* nlen) { struct ha_msg *tmpmsg; if (!value || !nv || depth < 0){ cl_log(LOG_ERR, "string2struct:invalid input"); return HA_FAIL; } if (convert(value, vallen, depth,SYM_TO_NL) != HA_OK){ cl_log(LOG_ERR , "ha_msg_addraw_ll(): convert failed"); return(HA_FAIL); } tmpmsg = string2msg_ll(value, vallen,depth + 1, 0); if (tmpmsg == NULL){ cl_log(LOG_ERR , "string2struct()" ": string2msg_ll failed"); return(HA_FAIL); } cl_free(value); *nv = tmpmsg; *nlen = 0; return HA_OK; }
/** * Deletes an AttributeList object. * * @param list Address of the pointer to the list to delete. */ int DestroyAttributeList(AttributeList **list) { AttributeInfo *ai; /* first, deallocate all members of the list */ ai = (*list)->list; while (ai) { AttributeInfo *ai2; ai2 = ai; ai = ai->next; cl_free(ai2->name); ai2->attribute = NULL; ai2->status = 0; ai2->next = NULL; ai2->prev = NULL; free(ai2); } (*list)->list = NULL; (*list)->list_valid = 0; (*list)->element_type = 0; free(*list); *list = NULL; return 1; }
void evidence_cl_free() { colorlist *test_cl = (colorlist*)malloc(sizeof(colorlist)); color *c1 = (color*)malloc(sizeof(color)); c1->r = 1; c1->g = 1; c1->b = 1; color *c2 = (color*)malloc(sizeof(color)); c2->r = 0; c2->g = 0.5; c2->b = 0.7; test_cl->c = *c1; colorlist *root = (colorlist*)malloc(sizeof(colorlist)); root->next = 0; root->c = *c2; test_cl->next = root; free(c1); free(c2); free(root); free(test_cl); cl_free(test_cl); printf("*** testing cl_free\n"); cl_print(test_cl); printf("\n"); }
void FreeChildLogIPCMessage(IPC_Message* msg) { if (msg == NULL) { return; } memset(msg->msg_body, 0, msg->msg_len); cl_free(msg->msg_buf); memset(msg, 0, sizeof (*msg)); cl_free(msg); childlog_ipcmsg_freed ++; return; }
LOCAL void dri_state_delete(dri_state_t *state) { if (state == NULL) return; dri_state_close(state); cl_free(state); }
Font& Font::operator = (const Font& f) { cl_free(self->name); self->name = cl_string_alloc(f.get_name()); self->size = f.get_size(); self->is_bold = f.get_is_bold(); return *this; }
/** * Scan email for virus. Returns 1 if virus * detected or 0 if no virus is detected. Sets * lscan.virname to virua or error output... */ int scan_clamav(char * scanpath) { sprintf(lscan.scanpath, "%s", scanpath); lscan.iNo = 0; /** lets load all our virus defs database's into memory */ lscan.root = NULL; /** without this line, the dbload will crash... */ if((lscan.i = cl_loaddbdir(cl_retdbdir(), &lscan.root, &lscan.iNo))) { sprintf(lscan.virname, "error: [%s]", cl_perror(lscan.i)); } else { if((lscan.i = cl_build(lscan.root))) { sprintf(lscan.virname, "database initialization error: [%s]", cl_perror(lscan.i)); cl_free(lscan.root); } memset(&lscan.limits, 0x0, sizeof(struct cl_limits)); lscan.limits.maxfiles = 1000; /** max files */ lscan.limits.maxfilesize = 10 * 1048576; /** maximal archived file size == 10 Mb */ lscan.limits.maxreclevel = 12; /** maximal recursion level */ lscan.limits.maxratio = 200; /** maximal compression ratio */ lscan.limits.archivememlim = 0; /** disable memory limit for bzip2 scanner */ if ((lscan.i = cl_scanfile(lscan.scanpath, (const char **)&lscan.virname, NULL, lscan.root, &lscan.limits, CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_BLOCKBROKEN | CL_SCAN_HTML | CL_SCAN_PE)) != CL_VIRUS) { if (lscan.i != CL_CLEAN) { sprintf(lscan.virname, "error: [%s]", cl_perror(lscan.i)); } else { lscan.virname = NULL; } } if (lscan.root != NULL) { cl_free(lscan.root); } memset(&lscan.limits, 0x0, sizeof(struct cl_limits)); } /** lets delete the spool message as we don't need it any more */ if (lscan.virname != NULL) { /** remove the file if we have a virus as we are going to reject it */ return(1); } else { /** else keep the file for spam filtering */ return(0); } return(1); } /** scan_clamav */
ImageData::~ImageData() { if(self) { cl_free(self->file); if(self->image) delete self->image; } cl_delete(self); }
/** * Resets right context scope of a ContextDescriptor to default (25 chars). */ void context_descriptor_reset_right_context(ContextDescriptor *cd) { if (cd) { cd->right_width = 25; cd->right_type = CHAR_CONTEXT; cl_free(cd->right_structure_name); } }
static void intel_driver_delete(intel_driver_t *driver) { if (driver == NULL) return; if (driver->bufmgr) drm_intel_bufmgr_destroy(driver->bufmgr); cl_free(driver); }