/* All ow library closeup */ void LibClose(void) { LEVEL_CALL("Starting Library cleanup"); LibStop(); PIDstop(); DeviceDestroy(); Detail_Close() ; _MUTEX_ATTR_DESTROY(Mutex.mattr); #if OW_ZERO // Used by browse and announce OW_Free_dnssd_library(); OW_Free_avahi_library(); #endif LEVEL_CALL("Finished Library cleanup"); if (log_available) { closelog(); log_available = 0; } SAFEFREE(Globals.announce_name) ; SAFEFREE(Globals.progname) ; SAFEFREE(Globals.fatal_debug_file) ; LEVEL_DEBUG("Libraries closed"); }
/** * @brief Is for error messages in the command line usage, * prints a invalid-argument error with a pre-defined * usage message. * * @param label Defined usage message label. * * @param error Type of command line usage error. */ void orcm_octl_usage(char *label, int error){ char *usage_msg = NULL; char *output = NULL; char *err_label = NULL; regex_t r_label; if (!regex_label( &r_label,"usage", label)) { usage_msg = search_msg(r_label); if (NULL != usage_msg) { // remove unnecessary last "\n" if (usage_msg[strlen(usage_msg)-1] == '\n') usage_msg[strlen(usage_msg)-1] = '\0'; asprintf(&output,"USAGE: %s" ,usage_msg); err_label = get_usage_label_error(error); if (NULL != output || NULL != err_label) orcm_octl_error(err_label, output); } regfree(&r_label); } SAFEFREE(output); SAFEFREE(usage_msg); SAFEFREE(err_label); }
STDMETHODIMP IsdbtCCDecode::Close() { InitClosedCaption(&m_tCaptionMgn); if(m_pFontDraw) { if(m_tOpenOption.OutputFormat==YV12) { for(unsigned int i=0;i<m_dwBufferNum;i++) { SAFEFREE(m_FrameBuffer[i].m_OutBuffer[0]); } } if(m_tOpenOption.OutputFormat==XRGB) { for(unsigned int i=0;i<m_dwBufferNum;i++) { SAFEFREE(m_FrameBuffer[i].m_OutBuffer[0]); } } SAFEFREE(m_FrameBuffer); m_FrameBuffer = 0; m_pFontDraw->Close(); delete m_pFontDraw; m_pFontDraw = NULL; } return S_OK; }
void FreeClientAddr(struct connection_in *in) { struct port_in * pin = in->pown ; SAFEFREE( pin->dev.tcp.host) ; SAFEFREE( pin->dev.tcp.service) ; if ( pin->dev.tcp.ai != NULL ) { freeaddrinfo( pin->dev.tcp.ai); pin->dev.tcp.ai = NULL; } pin->dev.tcp.ai_ok = NULL; }
/* ---------------------------------------------- */ void FS_ParsedName_destroy(struct parsedname *pn) { if (!pn) { return; } LEVEL_DEBUG("%s", SAFESTRING(pn->path)); CONNIN_RUNLOCK ; Detail_Free( pn ) ; SAFEFREE(pn->sparse_name); SAFEFREE(pn->bp) ; }
static void Browse_Struct_Destroy(struct BrowseStruct *browse_struct) { if ( browse_struct == NULL ) { return; } SAFEFREE(browse_struct->name ) ; SAFEFREE(browse_struct->type ) ; SAFEFREE(browse_struct->domain) ; owfree(browse_struct); }
static void push_query_result(PGresult* res, void* context, char* query) { struct push_info* push_info = (struct push_info*) context; int i; for (i = 0; i < PQntuples(res); i++) { if (!PQgetisnull(res, i, 0) && !PQgetisnull(res, i, 1)) { int type = atoi(PQgetvalue(res, i, 1)); if (type < amount_of_push_functions()) push_functions[type](push_info, PQgetvalue(res, i, 0), push_info->event_base); } } SAFEFREE(push_info->subject); SAFEFREE(push_info->data); SAFEFREE(push_info->sender); SAFEFREE(push_info); }
/* It does call lower level functions for higher ones, which of course is pointless since the lower ones don't work either */ GOOD_OR_BAD BadAdapter_detect(struct port_in *pin) { struct connection_in * in = pin->first ; pin->type = ct_none ; pin->file_descriptor = FILE_DESCRIPTOR_BAD ; in->Adapter = adapter_Bad; /* OWFS assigned value */ in->iroutines.reset = BadAdapter_reset; in->iroutines.next_both = NO_NEXT_BOTH_ROUTINE; in->iroutines.PowerByte = NO_POWERBYTE_ROUTINE; in->iroutines.ProgramPulse = NO_PROGRAMPULSE_ROUTINE; in->iroutines.sendback_data = NO_SENDBACKDATA_ROUTINE; in->iroutines.sendback_bits = BadAdapter_sendback_bits; in->iroutines.select = NO_SELECT_ROUTINE; in->iroutines.select_and_sendback = NO_SELECTANDSENDBACK_ROUTINE; in->iroutines.set_config = NO_SET_CONFIG_ROUTINE; in->iroutines.get_config = NO_GET_CONFIG_ROUTINE; in->iroutines.reconnect = NO_RECONNECT_ROUTINE; in->iroutines.close = BadAdapter_close; in->iroutines.verify = NO_VERIFY_ROUTINE ; in->iroutines.flags = ADAP_FLAG_sham; in->adapter_name = "Bad Adapter"; SAFEFREE( DEVICENAME(in) ) ; DEVICENAME(in) = owstrdup("None") ; pin->busmode = bus_bad ; return gbGOOD; }
static int workflow_list_unpack_buffer(orte_rml_recv_cb_t *xfer) { int workflow_count; int n; int workflow_id; char *workflow_name = NULL; int rc; int temp; n=1; if (ORCM_SUCCESS != (rc = opal_dss.unpack(&xfer->data, &workflow_count, &n, OPAL_INT))) { return rc; } for (temp = 0; temp < workflow_count; temp++) { if (ORCM_SUCCESS != (rc = opal_dss.unpack(&xfer->data, &workflow_id, &n, OPAL_INT))) { orcm_octl_error("unpack"); return rc; } if (ORCM_SUCCESS != (rc = opal_dss.unpack(&xfer->data, &workflow_name, &n, OPAL_STRING))) { orcm_octl_error("unpack"); return rc; } orcm_octl_info("workflow-list", workflow_name, workflow_id); SAFEFREE(workflow_name); } if (0 == workflow_count) { orcm_octl_info("no-workflows"); } return ORCM_SUCCESS; }
/** * @brief For error messages on octl operations, this will print a * pre-defined message to stderr. * * @param label Defined message label. */ void orcm_octl_error(char *label, ...){ static char *error_msg = NULL; const char *error_prepend = "ERROR: "; char output[MAX_SIZE]; regex_t r_label; memset(output, 0, MAX_SIZE); va_list var; va_start(var, label); if (!regex_label( &r_label,"error", label)) { error_msg = search_msg(r_label); if (NULL != error_msg) { snprintf(output, MAX_SIZE, "%s%s", error_prepend, error_msg); vfprintf(stderr, output, var); SAFEFREE(error_msg); } else { fprintf(stderr,"ERROR: Unkown error."); } regfree(&r_label); } else { fprintf(stderr,"ERROR: Unable to generate message."); } va_end(var); }
static orcm_value_t* compute_min(opal_list_t* compute, orcm_analytics_aggregate* aggregate, int workflow_id) { orcm_value_t *current_value = NULL; orcm_value_t *temp = NULL; orcm_value_t *min_value = NULL; char *data_key = NULL; double val; if(NULL == compute || NULL == aggregate) { return NULL; } temp = (orcm_value_t*)opal_list_get_first(compute); if(NULL != temp) { if (NULL == (data_key = generate_data_key("MIN", workflow_id))) { return NULL; } min_value = orcm_util_load_orcm_value(data_key, &temp->value.data,OPAL_DOUBLE,temp->units); } if(NULL == min_value){ SAFEFREE(data_key); return NULL; } min_value->value.data.dval = aggregate->min; OPAL_LIST_FOREACH(current_value, compute, orcm_value_t) { val = orcm_util_get_number_orcm_value(current_value); if(val < aggregate->min) { aggregate->min = val; min_value->value.data.dval = aggregate->min; } }
void delete_email(struct email* email) { if (email) { SAFEFREE(email->from); int i; for (i = 0; i < MAX_RECIPIENTS; i++) { if (email->to[i]) SAFEFREE(email->to[i]); else break; } SAFEFREE(email->subject); SAFEFREE(email->data); SAFEFREE(email); } }
/** * Let P be the patterns in a. Find p in patterns where |L(PU{p})| is smallest. * p returned is malloc()-ed. */ void * fa_find_least_countstr_plus(int m, fa * a, list * patterns) { void * best_p = NULL; _cnt_size best_p_coverage = CNT_SIZE_MAX_VALUE; _cnt_size coverage; listnode * node; letter * p; for (node = patterns->first; node; node = node->succ) { p = (letter *)node->data; coverage = fa_countstr_plus(m, a, p); if (coverage < 0) exit((int)-coverage); if (isinf(coverage)) { error("Overflow on \"%s\" with \"countstr(%d)\"\n", strcat(a->regex, pattern_to_regex((letter *)p)), m); exit(_EOVERFLOW); } else if (coverage < best_p_coverage) { if (best_p) SAFEFREE(best_p); best_p = worddup((letter *)p); best_p_coverage = coverage; } } return (void *)best_p; }
static void reset(void) { int i = 0; SAFEFREE(line); SAFEFREE(sline); /* if (field) { for(i = 0; i < max_field; i++) { SAFEFREE(field[i]); }*/ SAFEFREE(field); // } max_line = max_field = n_field; }
static void finalize(orcm_analytics_base_module_t *imod) { if (NULL != imod) { mca_analytics_aggregate_module_t *mod = (mca_analytics_aggregate_module_t *)imod; OBJ_RELEASE(mod->api.orcm_mca_analytics_data_store); SAFEFREE(mod); } }
/* Sent back from Bonjour -- arbitrarily use it to set the Ref for Deallocation */ static void RegisterBack(DNSServiceRef s, DNSServiceFlags f, DNSServiceErrorType e, const char *name, const char *type, const char *domain, void *v) { struct connection_out * out = v ; LEVEL_DETAIL ("RegisterBack ref=%d flags=%d error=%d name=%s type=%s domain=%s", s, f, e, SAFESTRING(name), SAFESTRING(type), SAFESTRING(domain)); if (e != kDNSServiceErr_NoError) { return ; } out->sref0 = s; SAFEFREE( out->zero.name ) ; out->zero.name = owstrdup(name) ; SAFEFREE( out->zero.type ) ; out->zero.type = owstrdup(type) ; SAFEFREE( out->zero.domain ) ; out->zero.domain = owstrdup(domain) ; }
static orcm_value_t *compute_average(opal_list_t *compute_data, orcm_analytics_aggregate* aggregate, int workflow_id) { double sum = 0.0; orcm_value_t *temp = NULL; orcm_value_t *aggregate_value = NULL; orcm_value_t *list_item = NULL; char *data_key = NULL; if (NULL == compute_data || NULL == aggregate) { return NULL; } size_t size = opal_list_get_size(compute_data); temp = (orcm_value_t*)opal_list_get_first(compute_data); if(NULL != temp) { if (NULL == (data_key = generate_data_key("average", workflow_id))) { return NULL; } aggregate_value = orcm_util_load_orcm_value(data_key, &temp->value.data,OPAL_DOUBLE,temp->units); } if(NULL == aggregate_value) { SAFEFREE(data_key); return NULL; } OPAL_LIST_FOREACH(list_item, compute_data, orcm_value_t) { if (NULL == list_item) { SAFEFREE(data_key); return NULL; } sum += orcm_util_get_number_orcm_value(list_item); } aggregate_value->value.data.dval = (aggregate->average * aggregate->num_sample + sum) / (aggregate->num_sample + size); aggregate->average = aggregate_value->value.data.dval; aggregate->num_sample += size; OPAL_OUTPUT_VERBOSE((5, orcm_analytics_base_framework.framework_output, "%s analytics:aggregate:AVERAGE is: %f, and the number of sample is:%u", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), aggregate->average,aggregate->num_sample)); SAFEFREE(data_key); return aggregate_value; }
int regex_label( regex_t *regex, char *type, char *label) { char *new_label = NULL; char *regex_exp = "^\\[%s\\:%s\\]"; int rc = 0; rc = asprintf(&new_label, regex_exp, type, label); if (NULL != new_label){ rc = regcomp(regex, new_label, REG_EXTENDED); SAFEFREE(new_label); } return rc; }
void FreeOutAll(void) { struct connection_out *next = Outbound_Control.head; struct connection_out *now; Outbound_Control.head = NULL; Outbound_Control.active = 0; while (next) { now = next; next = now->next; LEVEL_DEBUG("Freeing outbound %s #%d",now->zero.name,now->index); SAFEFREE(now->zero.name) ; SAFEFREE(now->zero.type) ; SAFEFREE(now->zero.domain) ; SAFEFREE(now->name) ; SAFEFREE(now->host) ; SAFEFREE(now->service) ; if (now->ai) { freeaddrinfo(now->ai); now->ai = NULL; } #if OW_ZERO if (libdnssd != NULL) { if (now->sref0) { DNSServiceRefDeallocate(now->sref0); } if (now->sref1) { DNSServiceRefDeallocate(now->sref1); } } #endif owfree(now); } }
static void workflow_process_error(opal_buffer_t *buf, orte_rml_recv_cb_t *xfer, char **list) { orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORCM_RML_TAG_ANALYTICS); if (NULL != buf) { OBJ_RELEASE(buf); } if (NULL != xfer) { OBJ_RELEASE(xfer); } SAFEFREE (list); }
int email_remove_email_from_recipients(struct email* email, char* addr) { int i; int output = 0; for (i = 0; i < MAX_RECIPIENTS; i++) { if (email->to[i] && string_equals(email->to[i], addr)) { SAFEFREE(email->to[i]); int j; for (j = i; j < MAX_RECIPIENTS; j++) email->to[j] = email->to[j+1]; output = 1; } } return output; }
static ZERO_OR_ERROR BranchAdd(struct parsedname *pn) { //printf("BRANCHADD\n"); if ((pn->ds2409_depth % BRANCH_INCR) == 0) { void *temp = pn->bp; if ((pn->bp = owrealloc(temp, (BRANCH_INCR + pn->ds2409_depth) * sizeof(struct ds2409_hubs))) == NULL) { SAFEFREE(temp) ; RETURN_CODE_RETURN( 79 ) ; // unable to allocate memory } } memcpy(pn->bp[pn->ds2409_depth].sn, pn->sn, SERIAL_NUMBER_SIZE); /* copy over DS2409 name */ pn->bp[pn->ds2409_depth].branch = pn->selected_filetype->data.i; ++pn->ds2409_depth; pn->selected_filetype = NO_FILETYPE; pn->selected_device = NO_DEVICE; return 0; }
/** * @brief Function that takes a string label and finds the message * related to the label in the "messages.txt" file. * * @param regex_label Pre-compiled message label pattern. * * @return char* Message or NULL if the message wasn't found. * DON'T FORGET TO FREE! */ char *search_msg(regex_t regex_label) { FILE *file = NULL; char line[MAX_SIZE] = {0,}; int regex_res = 0; char *msg = NULL; char *datadir = NULL; regex_t regex; asprintf(&datadir,"%s%s", opal_install_dirs.opaldatadir,"/help-octl.txt"); if(NULL != datadir) { regex_res = regcomp(®ex, next_label, REG_EXTENDED); file = fopen(datadir, "r"); if (NULL !=file) { if(!regex_res) { while (NULL != fgets(line, MAX_SIZE, file)) { regex_res = regexec(®ex_label, line, 0, NULL, 0); if (!regex_res){ msg = strdup("\0"); while (NULL != fgets(line, 1024, file) && NULL != msg) { if (!regexec(®ex, line, 0, NULL, 0)) { // remove unnecessary last "\n" if (msg[strlen(msg)-1] == '\n') { msg[strlen(msg)-1] = '\0'; } break; } else { msg = (char *) realloc(msg, strlen(msg) + strlen(line) + 1); if (NULL != msg){ strcat(msg, line); } } } break; } } regfree(®ex); } fclose(file); } SAFEFREE(datadir); } return msg; }
/** * @brief Function to show revelant information regarding the operation * executed on octl, this will print the message to standard output. * * @param label Defined message label. */ void orcm_octl_info(char *label, ...){ static char *info_msg = NULL; regex_t r_label; va_list var; va_start (var,label); if (!regex_label(&r_label, "info", label)) { info_msg = search_msg(r_label); if (NULL != info_msg) { vfprintf(stdout, info_msg, var); } regfree(&r_label); } va_end(var); SAFEFREE(info_msg); }
static void GetAllDeviceNames( struct port_in * pin ) { struct connection_in * in = pin->first ; ASCII * remaining_device_list = owstrdup( pin->init_data ) ; ASCII * remember_location = remaining_device_list ; while (remaining_device_list != NULL) { const ASCII *current_device_start; for (current_device_start = strsep(&remaining_device_list, " ,"); current_device_start[0] != '\0'; ++current_device_start) { // note that strsep updates "remaining_device_list" pointer if (current_device_start[0] != ' ' && current_device_start[0] != ',') { break; } } GetDeviceName( ¤t_device_start, in ) ; } SAFEFREE( remember_location ) ; in->AnyDevices = (DirblobElements(&(in->master.fake.main)) > 0) ? anydevices_yes : anydevices_no ; }
/* Return NULL if there is a problem */ char *DS9490_device_name(const struct usb_list *ul) { size_t len = 32 ; int sn_ret ; char * return_string = owmalloc(len+1); if ( return_string == NULL ) { return NULL ; } UCLIBCLOCK ; sn_ret = snprintf(return_string, len, "%.d:%.d", ul->usb_bus_number, ul->usb_dev_number) ; UCLIBCUNLOCK ; if (sn_ret <= 0) { SAFEFREE(return_string) ; } return return_string; }
static void SetConninData( int indx, const char * type, struct port_in *pin ) { struct connection_in * in = pin->first ; char name[20] ; pin->file_descriptor = indx; pin->type = ct_none ; in->master.fake.index = indx; in->master.fake.templow = Globals.templow; in->master.fake.temphigh = Globals.temphigh; LEVEL_CONNECT("Setting up %s Bus Master (%d)", type, indx); UCLIBCLOCK ; snprintf(name, 18, "%s.%d", type, indx); UCLIBCUNLOCK ; GetAllDeviceNames( pin ) ; // Device name and init_data diverge now SAFEFREE(DEVICENAME(in)) ; DEVICENAME(in) = owstrdup(name); }
static void check_email_to_callback(PGresult* res, void* context, char* query) { struct email* email = (struct email*) context; struct bufferevent* bev = email->bev; #ifdef DEV printf("Query %s returned with %d rows.\n", query, PQntuples(res)); #endif if (PQntuples(res) == 1) { size_t len = strlen(query); size_t email_len = len - TO_QUERY_START - TO_QUERY_END; char* addr = malloc(email_len); int i; for (i = 0; i <= email_len; i++) addr[i] = query[i + TO_QUERY_START]; addr[email_len] = '\0'; if (email_add_recipient(email, addr)) bufferevent_write(bev, _250_OK, strlen(_250_OK)); else { SAFEFREE(addr); bufferevent_write(bev, _550_NOT_ALLOWED, strlen(_550_NOT_ALLOWED)); } } else bufferevent_write(bev, _550_NOT_ALLOWED, strlen(_550_NOT_ALLOWED)); }
static orcm_value_t* compute_agg(char* op, char* data_key, opal_list_t* compute, orcm_analytics_aggregate* aggregate) { orcm_value_t *temp = NULL; orcm_value_t *agg_value = NULL; if(NULL == compute || NULL == aggregate || NULL == data_key) { return NULL; } temp = (orcm_value_t*)opal_list_get_first(compute); ON_NULL_RETURN(temp); agg_value = orcm_util_load_orcm_value(data_key, &temp->value.data,OPAL_DOUBLE,temp->units); ON_NULL_RETURN(agg_value); if(0 == strncmp(op,"average", strlen(op))) { compute_average(agg_value, aggregate, compute); } else if (0 == strncmp(op, "min", strlen(op))){ compute_min(agg_value, aggregate, compute); } else if (0 == strncmp(op,"max", strlen(op))){ compute_max(agg_value, aggregate, compute); } else { SAFEFREE(agg_value); } return agg_value; }
void FreeOutAll(void) { struct connection_out *next = Outbound_Control.head; struct connection_out *now; Outbound_Control.head = NULL; Outbound_Control.active = 0; while (next) { now = next; next = now->next; SAFEFREE(now->zero.name) ; SAFEFREE(now->zero.type) ; SAFEFREE(now->zero.domain) ; SAFEFREE(now->name) ; SAFEFREE(now->host) ; SAFEFREE(now->service) ; if (now->ai) { freeaddrinfo(now->ai); now->ai = NULL; } if ( FILE_DESCRIPTOR_VALID(now->file_descriptor) ) { shutdown(now->file_descriptor, SHUT_RDWR ) ; close(now->file_descriptor) ; } #if OW_ZERO if (libdnssd != NULL) { if (now->sref0) { DNSServiceRefDeallocate(now->sref0); } if (now->sref1) { DNSServiceRefDeallocate(now->sref1); } } #endif owfree(now); } }