From 7f645087b9d4a58413813dd551ef5a6e190d1146 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Tue, 15 May 2012 11:04:07 +0000 Subject: [PATCH] Debuggando gerenciamento de memória a procura de segfaults aleatórios --- XtGlue.c | 19 ++++++++----------- actions.c | 4 ++-- ansi.c | 2 +- charset.c | 10 +++++----- ft.c | 3 +-- ft_cut.c | 8 ++++---- ft_dft.c | 14 +++++++------- globals.h | 2 +- glue.c | 10 +++++----- host.c | 12 ++++++------ init.c | 2 +- kybd.c | 24 +++++++++++------------- localdefs.h | 4 ++-- macros.c | 8 ++++---- paste.c | 6 +++--- proxy.c | 46 +++++++++++++++++++++++----------------------- resources.c | 4 ++-- rpq.c | 6 +++--- selection.c | 14 +++++++------- telnet.c | 70 ++++++++++++++++++++++++++++++++++++---------------------------------- trace_ds.c | 24 ++++++++++++------------ utf8.c | 6 +++--- util.c | 32 ++++++++++++++++++-------------- 23 files changed, 165 insertions(+), 165 deletions(-) diff --git a/XtGlue.c b/XtGlue.c index e3f3ad0..77042e3 100644 --- a/XtGlue.c +++ b/XtGlue.c @@ -38,7 +38,7 @@ #include "globals.h" #include "api.h" -#include +// #include #if defined(_WIN32) #include "appres.h" @@ -179,8 +179,7 @@ static void * DefaultAddTimeOut(unsigned long interval_ms, H3270 *session, void Trace("%s session=%p proc=%p",__FUNCTION__,session,proc); - t_new = (timeout_t *)Malloc(sizeof(timeout_t)); - memset(t_new,0,sizeof(timeout_t)); + t_new = (timeout_t *) lib3270_malloc(sizeof(timeout_t)); t_new->proc = proc; t_new->session = session; @@ -244,7 +243,7 @@ static void DefaultRemoveTimeOut(void * timer) prev->next = t->next; else timeouts = t->next; - Free(t); + lib3270_free(t); return; } prev = t; @@ -268,8 +267,7 @@ static void * DefaultAddInput(int source, H3270 *session, void (*fn)(H3270 *sess Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - ip = (input_t *) Malloc(sizeof(input_t)); - memset(ip,0,sizeof(input_t)); + ip = (input_t *) lib3270_malloc(sizeof(input_t)); ip->source = source; ip->condition = InputReadMask; @@ -293,8 +291,7 @@ static void * DefaultAddExcept(int source, H3270 *session, void (*fn)(H3270 *ses Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - ip = (input_t *)Malloc(sizeof(input_t)); - memset(ip,0,sizeof(input_t)); + ip = (input_t *) lib3270_malloc(sizeof(input_t)); ip->source = source; ip->condition = InputExceptMask; @@ -317,7 +314,7 @@ static void * DefaultAddOutput(int source, H3270 *session, void (*fn)(H3270 *ses Trace("%s session=%p proc=%p",__FUNCTION__,session,fn); - ip = (input_t *)Malloc(sizeof(input_t)); + ip = (input_t *)lib3270_malloc(sizeof(input_t)); memset(ip,0,sizeof(input_t)); ip->source = source; @@ -356,7 +353,7 @@ static void DefaultRemoveInput(void *id) else inputs = ip->next; - Free(ip); + lib3270_free(ip); inputs_changed = True; } @@ -545,7 +542,7 @@ static int DefaultProcessEvents(int block) t->in_play = True; (*t->proc)(t->session); processed_any = True; - Free(t); + lib3270_free(t); } else break; } diff --git a/actions.c b/actions.c index 472c505..84e7f82 100644 --- a/actions.c +++ b/actions.c @@ -163,10 +163,10 @@ action_internal(XtActionProc action, enum iaction cause, const char *parm1, // Free the parm copies. switch (count) { case 2: - Free(parms[1]); + lib3270_free(parms[1]); // fall through... case 1: - Free(parms[0]); + lib3270_free(parms[0]); break; default: break; diff --git a/ansi.c b/ansi.c index 07dda82..6728a28 100644 --- a/ansi.c +++ b/ansi.c @@ -600,7 +600,7 @@ ansi_reset(int ig1 unused, int ig2 unused) saved_altbuffer = False; scroll_top = 1; scroll_bottom = h3270.rows; - Replace(tabs, (unsigned char *)Malloc((h3270.cols+7)/8)); + Replace(tabs, (unsigned char *)lib3270_malloc((h3270.cols+7)/8)); for (i = 0; i < (h3270.cols+7)/8; i++) tabs[i] = 0x01; held_wrap = False; diff --git a/charset.c b/charset.c index d9c841a..63d37b0 100644 --- a/charset.c +++ b/charset.c @@ -227,7 +227,7 @@ enum cs_result charset_init(H3270 *session, const char *csname) // Grab the non-Euro definition. basename = xs_buffer("%.*s", (int) (strlen(csname) - ES_SIZE), csname); cs = get_charset_def(basename); - Free(basename); + lib3270_free(basename); } */ if (!ccs) @@ -251,8 +251,8 @@ enum cs_result charset_init(H3270 *session, const char *csname) rc = resource_charset(csname, ccs, cftcs); /* Free them. */ - Free(ccs); - Free(cftcs); + lib3270_free(ccs); + lib3270_free(cftcs); #if defined(DEBUG_CHARSET) /*[*/ if (rc == CS_OKAY) @@ -340,7 +340,7 @@ static void set_cgcsgids(const char *spec) } n_ids++; } - Free(spec_copy); + lib3270_free(spec_copy); if (n_ids > 0) return; } @@ -681,7 +681,7 @@ static enum cs_result remap_chars(const char *csname, char *spec, remap_scope sc remap_one(ebc, iso, scope, one_way); } } - Free(spec); + lib3270_free(spec); return rc; } diff --git a/ft.c b/ft.c index af21147..89299d9 100644 --- a/ft.c +++ b/ft.c @@ -340,8 +340,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); ft_last_cr = False; ft_is_cut = False; - ftHandle = malloc(sizeof(H3270FT)); - memset(ftHandle,0,sizeof(H3270FT)); + ftHandle = lib3270_malloc(sizeof(H3270FT)); ftHandle->sz = sizeof(H3270FT); ftHandle->host = session; diff --git a/ft_cut.c b/ft_cut.c index fc03b40..769bc36 100644 --- a/ft_cut.c +++ b/ft_cut.c @@ -36,7 +36,7 @@ */ #include -#include +// #include #include "globals.h" @@ -340,7 +340,7 @@ cut_control_code(void) } else { - bp = buf = Malloc(81); + bp = buf = lib3270_malloc(81); for (i = 0; i < 80; i++) *bp++ = ebc2asc[h3270.ea_buf[O_CC_MESSAGE + i].cc]; @@ -360,7 +360,7 @@ cut_control_code(void) strcpy(buf, N_( "Transfer cancelled by host" ) ); } ft_complete(NULL,buf); - Free(buf); + lib3270_free(buf); break; default: @@ -528,7 +528,7 @@ static void cut_abort(unsigned short reason, const char *fmt, ...) va_list args; if(saved_errmsg) - free(saved_errmsg); + lib3270_free(saved_errmsg); /* Save the error message. */ va_start(args, fmt); diff --git a/ft_dft.c b/ft_dft.c index 06a99f3..9e619f2 100644 --- a/ft_dft.c +++ b/ft_dft.c @@ -55,7 +55,7 @@ #include "utilc.h" #include -#include +// #include extern unsigned char aid; @@ -243,7 +243,7 @@ dft_data_insert(struct data_buffer *data_bufr) unsigned char *dollarp; /* Get storage to copy the message. */ - msgp = (unsigned char *)Malloc(my_length + 1); + msgp = (unsigned char *)lib3270_malloc(my_length + 1); /* Copy the message. */ memcpy(msgp, data_bufr->data, my_length); @@ -257,15 +257,15 @@ dft_data_insert(struct data_buffer *data_bufr) /* If transfer completed ok, use our msg. */ if (memcmp(msgp, END_TRANSFER, strlen(END_TRANSFER)) == 0) { - Free(msgp); + lib3270_free(msgp); ft_complete(NULL,NULL); } else if (lib3270_get_ft_state(&h3270) == FT_ABORT_SENT && abort_string != CN) { - Free(msgp); + lib3270_free(msgp); ft_complete(NULL,abort_string); Replace(abort_string, CN); } else { ft_complete(NULL,(char *)msgp); - Free(msgp); + lib3270_free(msgp); } } else if (my_length > 0) { /* Write the data out to the file. */ @@ -459,7 +459,7 @@ dft_get_request(void) dft_savebuf_len = obptr - obuf; if (dft_savebuf_len > dft_savebuf_max) { dft_savebuf_max = dft_savebuf_len; - Replace(dft_savebuf, (unsigned char *)Malloc(dft_savebuf_max)); + Replace(dft_savebuf, (unsigned char *)lib3270_malloc(dft_savebuf_max)); } (void) memcpy(dft_savebuf, obuf, dft_savebuf_len); aid = AID_SF; @@ -494,7 +494,7 @@ static void dft_abort(unsigned short code, const char *fmt, ...) va_list args; if(abort_string) - free(abort_string); + lib3270_free(abort_string); va_start(args, fmt); abort_string = xs_vsprintf(fmt, args); diff --git a/globals.h b/globals.h index f691c54..b77e997 100644 --- a/globals.h +++ b/globals.h @@ -318,7 +318,7 @@ LIB3270_INTERNAL struct trans_list *trans_list; #define CN ((char *) NULL) #define PN ((XtPointer) NULL) -#define Replace(var, value) { Free(var); var = (value); } +#define Replace(var, value) { lib3270_free(var); var = (value); } /* Configuration change masks. */ #define NO_CHANGE 0x0000 /* no change */ diff --git a/glue.c b/glue.c index b67883d..b58b0ca 100644 --- a/glue.c +++ b/glue.c @@ -563,7 +563,7 @@ parse_xrm(const char *arg, const char *where) type = resources[i].type; #if defined(C3270) /*[*/ if (address == NULL) { - add_buf = Malloc(strlen(s) + 1); + add_buf = lib3270_malloc(strlen(s) + 1); address = add_buf; } #endif /*]*/ @@ -619,7 +619,7 @@ parse_xrm(const char *arg, const char *where) } break; case XRM_STRING: - t = Malloc(strlen(s) + 1); + t = lib3270_malloc(strlen(s) + 1); *(char **)address = t; if (*s == '"') { Boolean quoted = False; @@ -675,7 +675,7 @@ parse_xrm(const char *arg, const char *where) if (arbitrary) { char *rsname; - rsname = Malloc(rnlen + 1); + rsname = lib3270_malloc(rnlen + 1); (void) strncpy(rsname, arg + match_len, rnlen); rsname[rnlen] = '\0'; add_resource(rsname, hide); @@ -702,7 +702,7 @@ read_resource_file(const char *filename, Boolean fatal) } /* Merge in what's in the file into the resource database. */ - where = Malloc(strlen(filename) + 64); + where = lib3270_malloc(strlen(filename) + 64); ilen = 0; while (fgets(buf + ilen, sizeof(buf) - ilen, f) != CN || ilen) { @@ -783,7 +783,7 @@ read_resource_file(const char *filename, Boolean fatal) /* Get ready for the next iteration. */ ilen = 0; } - Free(where); + lib3270_free(where); return 0; } diff --git a/host.c b/host.c index 441bc83..5ee7c02 100644 --- a/host.c +++ b/host.c @@ -52,7 +52,7 @@ #include "xioc.h" #include -#include +// #include #define RECONNECT_MS 2000 /* 2 sec before reconnecting to host */ #define RECONNECT_ERR_MS 5000 /* 5 sec before reconnecting to host */ @@ -124,10 +124,10 @@ hostfile_init(void) ResHostsFile); continue; } - h = (struct host *)Malloc(sizeof(*h)); + h = (struct host *)lib3270_malloc(sizeof(*h)); if (!split_hier(NewString(name), &h->name, &h->parents)) { - Free(h); + lib3270_free(h); continue; } h->hostname = NewString(hostname); @@ -160,7 +160,7 @@ hostfile_init(void) popup_an_errno(errno, "Cannot open " ResHostsFile " '%s'", appres.hostsfile); } - Free(hostfile_name); + lib3270_free(hostfile_name); // #if defined(X3270_DISPLAY) // save_recent(CN); @@ -465,7 +465,7 @@ split_host(H3270 *hSession, char *s, char *ansi, char *std_ds, char *passthru, goto split_success; split_fail: - Free(r); + lib3270_free(r); r = CN; split_success: @@ -803,7 +803,7 @@ LIB3270_EXPORT const char * lib3270_set_host(H3270 *h, const char *n) trace("new hostname is \"%s\"",new_hostname); if(h->full_current_host) - free(h->full_current_host); + lib3270_free(h->full_current_host); h->full_current_host = new_hostname; diff --git a/init.c b/init.c index 6c94bfc..a6e4e45 100644 --- a/init.c +++ b/init.c @@ -61,7 +61,7 @@ void lib3270_session_free(H3270 *h) while(h->st_callbacks[f]) { struct lib3270_state_callback *next = h->st_callbacks[f]->next; - Free(h->st_callbacks[f]); + lib3270_free(h->st_callbacks[f]); h->st_callbacks[f] = next; } } diff --git a/kybd.c b/kybd.c index d2e58ec..78954ff 100644 --- a/kybd.c +++ b/kybd.c @@ -222,9 +222,7 @@ static int enq_chk(void) if(enq_chk()) return; - ta = (struct ta *) Malloc(sizeof(*ta)); - memset(ta,0,sizeof(struct ta)); - + ta = (struct ta *) lib3270_malloc(sizeof(*ta)); ta->next = (struct ta *) NULL; ta->type = TA_TYPE_KEY_AID; ta->aid_code = aid_code; @@ -257,8 +255,7 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char CHECK_SESSION_HANDLE(hSession); - ta = (struct ta *) Malloc(sizeof(*ta)); - memset(ta,0,sizeof(struct ta)); + ta = (struct ta *) lib3270_malloc(sizeof(*ta)); ta->session = hSession; ta->next = (struct ta *) NULL; ta->type = TA_TYPE_DEFAULT; @@ -277,7 +274,7 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char else { ta_head = ta; - status_typeahead(&h3270,True); + status_typeahead(hSession,True); } ta_tail = ta; @@ -304,9 +301,8 @@ Boolean run_ta(void) { case TA_TYPE_DEFAULT: ta->fn(ta->session,ta->parm[0],ta->parm[1]); - Free(ta->parm[0]); - Free(ta->parm[1]); - Free(ta); + lib3270_free(ta->parm[0]); + lib3270_free(ta->parm[1]); break; case TA_TYPE_KEY_AID: @@ -319,6 +315,8 @@ Boolean run_ta(void) } + lib3270_free(ta); + return True; } @@ -334,10 +332,10 @@ flush_ta(void) for (ta = ta_head; ta != (struct ta *) NULL; ta = next) { - Free(ta->parm[0]); - Free(ta->parm[1]); + lib3270_free(ta->parm[0]); + lib3270_free(ta->parm[1]); next = ta->next; - Free(ta); + lib3270_free(ta); any = True; } ta_head = ta_tail = (struct ta *) NULL; @@ -3466,7 +3464,7 @@ void clear_xks(void) { if (nxk) { - Free(xk); + lib3270_free(xk); xk = (struct xks *)NULL; nxk = 0; } diff --git a/localdefs.h b/localdefs.h index 4e94fb9..0883085 100644 --- a/localdefs.h +++ b/localdefs.h @@ -68,8 +68,8 @@ typedef struct _XtActionsRec{ // void * Calloc(size_t, size_t); // void * Realloc(void *, size_t); -#define Malloc(x) lib3270_malloc(x) -#define Free(x) lib3270_free(x) +// #define Malloc(x) lib3270_malloc(x) +// #define Free(x) lib3270_free(x) #define Calloc(e,n) lib3270_calloc(e,n,NULL) #define Realloc(x,n) lib3270_realloc(x,n) diff --git a/macros.c b/macros.c index 4e8c46d..19f0283 100644 --- a/macros.c +++ b/macros.c @@ -33,7 +33,7 @@ #include #include #include - #include +// #include #include #include #include @@ -113,7 +113,7 @@ case 1: // Get entire screen lib3270_get_screen_size(hSession,&rows,&cols); qtd = (rows*(cols+1)+1); - buffer = malloc(qtd+2); + buffer = lib3270_malloc(qtd+2); memset(buffer,0,qtd+1); start = qtd = 0; @@ -165,7 +165,7 @@ return NULL; } - buffer = malloc(qtd+1); + buffer = lib3270_malloc(qtd+1); screen_read(buffer, start, qtd); */ @@ -231,7 +231,7 @@ host = "-"; sz = strlen(luname)+strlen(state)+strlen(host)+4; - rsp = malloc(sz+1); + rsp = lib3270_malloc(sz+1); snprintf(rsp,sz,"%s %s %s",state,luname,host); return rsp; } diff --git a/paste.c b/paste.c index 52a5e2e..2d26de0 100644 --- a/paste.c +++ b/paste.c @@ -45,7 +45,7 @@ #endif #include -#include +// #include #include "3270ds.h" #include "appres.h" @@ -254,7 +254,7 @@ LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) if(h->paste_buffer) { - free(h->paste_buffer); + lib3270_free(h->paste_buffer); h->paste_buffer = NULL; } @@ -296,6 +296,6 @@ LIB3270_ACTION(pastenext) rc = lib3270_paste(hSession,(unsigned char *) ptr); - free(ptr); + lib3270_free(ptr); return rc; } diff --git a/proxy.c b/proxy.c index 21c7b0e..0e78487 100644 --- a/proxy.c +++ b/proxy.c @@ -56,7 +56,7 @@ #else - #include +// #include #include #include #include @@ -306,7 +306,7 @@ parse_host_port(char *s, char **phost, char **pport) *pport = NewString(colon + 1); /* Copy out the hostname. */ - *phost = Malloc(hlen + 1); + *phost = lib3270_malloc(hlen + 1); strncpy(*phost, hstart, hlen); (*phost)[hlen] = '\0'; return 0; @@ -347,7 +347,7 @@ proxy_passthru(int fd, char *host, unsigned short port) { char *buf; - buf = Malloc(strlen(host) + 32); + buf = lib3270_malloc(strlen(host) + 32); (void) sprintf(buf, "%s %u\r\n", host, port); #if defined(X3270_TRACE) /*[*/ @@ -357,10 +357,10 @@ proxy_passthru(int fd, char *host, unsigned short port) if (send(fd, buf, strlen(buf), 0) < 0) { popup_a_sockerr(NULL,"Passthru Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } - Free(buf); + lib3270_free(buf); return 0; } @@ -377,7 +377,7 @@ proxy_http(int fd, char *host, unsigned short port) char *space; /* Send the CONNECT request. */ - buf = Malloc(64 + strlen(host)); + buf = lib3270_malloc(64 + strlen(host)); colon = strchr(host, ':'); sprintf(buf, "CONNECT %s%s%s:%u HTTP/1.1\r\n", (colon? "[": ""), @@ -392,7 +392,7 @@ proxy_http(int fd, char *host, unsigned short port) if (send(fd, buf, strlen(buf), 0) < 0) { popup_a_sockerr(NULL,"HTTP Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } @@ -409,7 +409,7 @@ proxy_http(int fd, char *host, unsigned short port) if (send(fd, buf, strlen(buf), 0) < 0) { popup_a_sockerr(NULL,"HTTP Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } @@ -421,10 +421,10 @@ proxy_http(int fd, char *host, unsigned short port) if (send(fd, buf, strlen(buf), 0) < 0) { popup_a_sockerr(NULL,"HTTP Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } - Free(buf); + lib3270_free(buf); /* * Process the reply. @@ -498,7 +498,7 @@ proxy_telnet(int fd, char *host, unsigned short port) { char *buf; - buf = Malloc(strlen(host) + 32); + buf = lib3270_malloc(strlen(host) + 32); (void) sprintf(buf, "connect %s %u\r\n", host, port); #if defined(X3270_TRACE) /*[*/ @@ -508,10 +508,10 @@ proxy_telnet(int fd, char *host, unsigned short port) if (send(fd, buf, strlen(buf), 0) < 0) { popup_a_sockerr(NULL,"TELNET Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } - Free(buf); + lib3270_free(buf); return 0; } @@ -558,7 +558,7 @@ proxy_socks4(int fd, char *host, unsigned short port, int force_a) /* Send the request to the server. */ if (use_4a) { - buf = Malloc(32 + strlen(user) + strlen(host)); + buf = lib3270_malloc(32 + strlen(user) + strlen(host)); s = buf; *s++ = 0x04; *s++ = 0x01; @@ -578,14 +578,14 @@ proxy_socks4(int fd, char *host, unsigned short port, int force_a) if (send(fd, buf, s - buf, 0) < 0) { popup_a_sockerr(NULL,"SOCKS4 Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } - Free(buf); + lib3270_free(buf); } else { unsigned long u; - buf = Malloc(32 + strlen(user)); + buf = lib3270_malloc(32 + strlen(user)); s = buf; *s++ = 0x04; *s++ = 0x01; @@ -603,11 +603,11 @@ proxy_socks4(int fd, char *host, unsigned short port, int force_a) #endif /*]*/ if (send(fd, buf, s - buf, 0) < 0) { - Free(buf); + lib3270_free(buf); popup_a_sockerr(NULL,"SOCKS4 Proxy: send error"); return -1; } - Free(buf); + lib3270_free(buf); } /* @@ -799,7 +799,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) } /* Send the request to the server. */ - buf = Malloc(32 + strlen(host)); + buf = lib3270_malloc(32 + strlen(host)); s = buf; *s++ = 0x05; /* protocol version 5 */ *s++ = 0x01; /* CONNECT */ @@ -836,10 +836,10 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) if (send(fd, buf, s - buf, 0) < 0) { popup_a_sockerr(NULL,"SOCKS5 Proxy: send error"); - Free(buf); + lib3270_free(buf); return -1; } - Free(buf); + lib3270_free(buf); /* * Process the reply. @@ -1009,7 +1009,7 @@ proxy_socks5(int fd, char *host, unsigned short port, int force_d) nbuf, rport); #endif /*]*/ - Free(buf); + lib3270_free(buf); return 0; } diff --git a/resources.c b/resources.c index 9f52c18..3577406 100644 --- a/resources.c +++ b/resources.c @@ -118,7 +118,7 @@ void add_resource(const char *name, const char *value) return; } } - d = Malloc(sizeof(struct dresource)); + d = lib3270_malloc(sizeof(struct dresource)); d->next = NULL; d->name = name; d->value = value; @@ -175,7 +175,7 @@ const char * get_fresource(const char *fmt, ...) name = xs_vsprintf(fmt, args); va_end(args); r = get_resource(name); - Free(name); + lib3270_free(name); return r; } diff --git a/rpq.c b/rpq.c index 4edc475..a679006 100644 --- a/rpq.c +++ b/rpq.c @@ -282,7 +282,7 @@ select_rpq_terms(void) * If there are override values, I'll get those from the ORIGINAL * string so upper/lower case is preserved as necessary. */ - uplist = (char *) malloc(strlen(x3270rpq)+1); + uplist = (char *) lib3270_malloc(strlen(x3270rpq)+1); assert(uplist != NULL); p1 = uplist; p2 = x3270rpq; @@ -594,7 +594,7 @@ get_rpq_address(unsigned char *buf, const int maxlen) #endif /*]*/ p1 = x3270rpq + kw->oride; - rpqtext = (char *) malloc(strlen(p1) + 1); + rpqtext = (char *) lib3270_malloc(strlen(p1) + 1); for (p2=rpqtext;*p1; p2++) { if (*p1 == ':') break; @@ -729,7 +729,7 @@ static void rpq_warning(const char *fmt, ...) { va_start(a, fmt); if (rpq_warnbuf == CN) - rpq_warnbuf = Malloc(RPQ_WARNBUF_SIZE); + rpq_warnbuf = lib3270_malloc(RPQ_WARNBUF_SIZE); if (rpq_wbcnt < RPQ_WARNBUF_SIZE) { diff --git a/selection.c b/selection.c index 03ac089..497935a 100644 --- a/selection.c +++ b/selection.c @@ -29,7 +29,7 @@ #include "globals.h" #include "appres.h" - #include +// #include #include #include #include @@ -382,7 +382,7 @@ static char * get_text(H3270 *hSession,unsigned char all) if(!lib3270_connected(hSession)) return NULL; - ret = malloc(buflen); + ret = lib3270_malloc(buflen); baddr = 0; for(row=0;row < hSession->rows;row++) @@ -405,14 +405,14 @@ static char * get_text(H3270 *hSession,unsigned char all) if(!sz) { - free(ret); + lib3270_free(ret); return NULL; } ret[sz++] = 0; if(sz != buflen) - ret = realloc(ret,sz); + ret = lib3270_realloc(ret,sz); return ret; } @@ -434,7 +434,7 @@ LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, u if(start_pos < 0 || start_pos > maxlen || end_pos < 0 || end_pos > maxlen || end_pos < start_pos) return NULL; - text = malloc(maxlen); + text = lib3270_malloc(maxlen); for(baddr=start_pos;baddr maxlen) len = maxlen; - buffer = malloc(len+1); + buffer = lib3270_malloc(len+1); ptr = buffer; // trace("len=%d buffer=%p",len,buffer); diff --git a/telnet.c b/telnet.c index 8708743..8211340 100644 --- a/telnet.c +++ b/telnet.c @@ -162,10 +162,7 @@ static unsigned char *sbbuf = (unsigned char *)NULL; /* telnet sub-option buffer */ static unsigned char *sbptr; static unsigned char telnet_state; -static int syncing; -#if !defined(_WIN32) /*[*/ -static unsigned long output_id = 0L; -#endif /*]*/ +// static int syncing; static char ttype_tmpval[13]; #if defined(X3270_TN3270E) /*[*/ @@ -514,7 +511,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo #endif if (netrbuf == (unsigned char *)NULL) - netrbuf = (unsigned char *)Malloc(BUFSZ); + netrbuf = (unsigned char *)lib3270_malloc(BUFSZ); #if defined(X3270_ANSI) /*[*/ if (!t_valid) @@ -690,7 +687,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo msg, "%s",strerror(rc) ); - Free(msg); + lib3270_free(msg); close_fail; } @@ -775,8 +772,7 @@ setup_lus(void) * Allocate enough memory to construct an argv[] array for * the LUs. */ - Replace(lus, - (char **)Malloc((n_lus+1) * sizeof(char *) + strlen(h3270.luname) + 1)); + Replace(lus,(char **)lib3270_malloc((n_lus+1) * sizeof(char *) + strlen(h3270.luname) + 1)); /* Copy each LU into the array. */ lu = (char *)(lus + n_lus + 1); @@ -884,7 +880,7 @@ static void net_connected(H3270 *session) ns_rrcvd = 0; ns_bsent = 0; ns_rsent = 0; - syncing = 0; + session->syncing = 0; tn3270e_negotiated = 0; tn3270e_submode = E_NONE; tn3270e_bound = 0; @@ -898,10 +894,10 @@ static void net_connected(H3270 *session) { char *buf; - buf = Malloc(strlen(session->hostname) + 32); + buf = lib3270_malloc(strlen(session->hostname) + 32); (void) sprintf(buf, "%s %d\r\n", session->hostname, session->current_port); (void) send(session->sock, buf, strlen(buf), 0); - Free(buf); + lib3270_free(buf); } } @@ -956,14 +952,17 @@ void net_disconnect(H3270 *session) session->connected_lu = CN; status_lu(&h3270,CN); -#if !defined(_WIN32) /*[*/ - /* We have no more interest in output buffer space. */ - if (output_id != 0L) +/* +#if !defined(_WIN32) + // We have no more interest in output buffer space. + if(session->output_id != NULL) { - RemoveInput(output_id); - output_id = 0L; + RemoveInput(session->output_id); + session->output_id = NULL; } -#endif /*]*/ +#endif +*/ + } @@ -1232,7 +1231,8 @@ telnet_fsm(unsigned char c) ansi_data = 4 + sl; } trace_dsn("%s",see_chr); - if (!syncing) { + if (!h3270.syncing) + { if (linemode && h3270.onlcr && c == '\n') ansi_process((unsigned int) '\r'); ansi_process((unsigned int) c); @@ -1295,14 +1295,14 @@ telnet_fsm(unsigned char c) case SB: telnet_state = TNS_SB; if (sbbuf == (unsigned char *)NULL) - sbbuf = (unsigned char *)Malloc(1024); + sbbuf = (unsigned char *)lib3270_malloc(1024); sbptr = sbbuf; break; case DM: trace_dsn("\n"); - if (syncing) + if (h3270.syncing) { - syncing = 0; + h3270.syncing = 0; x_except_on(&h3270); } telnet_state = TNS_DATA; @@ -1480,7 +1480,7 @@ telnet_fsm(unsigned char c) status_lu(&h3270,h3270.connected_lu); tb_len = 4 + tt_len + 2; - tt_out = Malloc(tb_len + 1); + tt_out = lib3270_malloc(tb_len + 1); (void) sprintf(tt_out, "%c%c%c%c%s%s%s%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_IS, h3270.termtype, @@ -1494,7 +1494,7 @@ telnet_fsm(unsigned char c) telquals[TELQUAL_IS], tt_len, tt_out + 4, cmd(SE)); - Free(tt_out); + lib3270_free(tt_out); /* Advance to the next LU name. */ next_lu(); @@ -1536,7 +1536,7 @@ tn3270e_request(void) tt_len += strlen(try_lu) + 1; tb_len = 5 + tt_len + 2; - tt_out = Malloc(tb_len + 1); + tt_out = lib3270_malloc(tb_len + 1); t = tt_out; t += sprintf(tt_out, "%c%c%c%c%c%s", IAC, SB, TELOPT_TN3270E, TN3270E_OP_DEVICE_TYPE, @@ -1559,7 +1559,7 @@ tn3270e_request(void) (try_lu != CN && *try_lu) ? try_lu : "", cmd(SE)); - Free(tt_out); + lib3270_free(tt_out); } /* @@ -1884,7 +1884,7 @@ process_bind(unsigned char *buf, int buflen) static int process_eor(void) { - if (syncing || !(ibptr - ibuf)) + if (h3270.syncing || !(ibptr - ibuf)) return(0); #if defined(X3270_TN3270E) /*[*/ @@ -1968,15 +1968,17 @@ process_eor(void) */ void net_exception(H3270 *session) { + CHECK_SESSION_HANDLE(session); + trace_dsn("RCVD urgent data indication\n"); - if (!syncing) + if (!session->syncing) { - syncing = 1; + session->syncing = 1; if(session->excepting) { RemoveInput(session->ns_exception_id); - session->excepting = False; + session->excepting = 0; } // x_except_off(session); } @@ -2105,7 +2107,7 @@ net_hexansi_out(unsigned char *buf, int len) #endif /*]*/ /* Expand it. */ - tbuf = xbuf = (unsigned char *)Malloc(2*len); + tbuf = xbuf = (unsigned char *)lib3270_malloc(2*len); while (len) { unsigned char c = *buf++; @@ -2119,7 +2121,7 @@ net_hexansi_out(unsigned char *buf, int len) /* Send it to the host. */ net_rawout(xbuf, tbuf - xbuf); - Free(xbuf); + lib3270_free(xbuf); } /* @@ -2212,7 +2214,7 @@ static void cooked_init(void) { if (lbuf == (unsigned char *)NULL) - lbuf = (unsigned char *)Malloc(BUFSZ); + lbuf = (unsigned char *)lib3270_malloc(BUFSZ); lbptr = lbuf; lnext = 0; backslashed = 0; @@ -2486,7 +2488,7 @@ check_in3270(void) /* Allocate the initial 3270 input buffer. */ if (new_cstate >= CONNECTED_INITIAL && !ibuf_size) { - ibuf = (unsigned char *)Malloc(BUFSIZ); + ibuf = (unsigned char *)lib3270_malloc(BUFSIZ); ibuf_size = BUFSIZ; ibptr = ibuf; } @@ -2726,7 +2728,7 @@ net_output(void) need_resize++; } if (need_resize) { - Replace(xobuf, (unsigned char *)Malloc(xobuf_len)); + Replace(xobuf, (unsigned char *)lib3270_malloc(xobuf_len)); } /* Copy and expand IACs. */ diff --git a/trace_ds.c b/trace_ds.c index 787dd61..56d80bd 100644 --- a/trace_ds.c +++ b/trace_ds.c @@ -421,7 +421,7 @@ static char * create_tracefile_header(const char *mode) time_t clk; // Create a buffer and redirect output. - buf = Malloc(MAX_HEADER_SIZE); + buf = lib3270_malloc(MAX_HEADER_SIZE); tracef_bufptr = buf; // Display current status @@ -583,7 +583,7 @@ static void tracefile_callback(Widget w, XtPointer client_data, XtPointer call_d if (strchr(tfn, '\'') || ((int)strlen(tfn) > 0 && tfn[strlen(tfn)-1] == '\\')) { popup_an_error("Illegal file name: %s", tfn); - Free(tfn); + lib3270_free(tfn); return; } @@ -604,7 +604,7 @@ static void tracefile_callback(Widget w, XtPointer client_data, XtPointer call_d if (tracef_max && !access(tfn, R_OK)) { popup_an_error("Trace file '%s' already exists",tfn); - Free(tfn); + lib3270_free(tfn); return; } @@ -616,7 +616,7 @@ static void tracefile_callback(Widget w, XtPointer client_data, XtPointer call_d if (tracef == (FILE *)NULL) { popup_an_errno(errno, tfn); - Free(tfn); + lib3270_free(tfn); return; } (void) SETLINEBUF(tracef); @@ -629,7 +629,7 @@ static void tracefile_callback(Widget w, XtPointer client_data, XtPointer call_d if(!tracewindow_handle) tracewindow_handle = console_window_new( tfn, NULL ); - Free(tfn); + lib3270_free(tfn); // We're really tracing, turn the flag on. appres.toggle[trace_reason].value = True; @@ -639,7 +639,7 @@ static void tracefile_callback(Widget w, XtPointer client_data, XtPointer call_d // Display current status buf = create_tracefile_header("started"); wtrace("%s", buf); - Free(buf); + lib3270_free(buf); } @@ -696,7 +696,7 @@ tracefile_on(int reason, LIB3270_TOGGLE_TYPE tt) { tracefile_callback((Widget)NULL, tracefile, PN); if (tracefile_buf != NULL) - Free(tracefile_buf); + lib3270_free(tracefile_buf); return; } #if defined(X3270_DISPLAY) @@ -718,7 +718,7 @@ tracefile_on(int reason, LIB3270_TOGGLE_TYPE tt) #endif if (tracefile_buf != NULL) - Free(tracefile_buf); + lib3270_free(tracefile_buf); } // Close the trace file. @@ -856,10 +856,10 @@ screentrace_cb(char *tfn) screentracef = fopen(tfn, "a"); if (screentracef == (FILE *)NULL) { popup_an_errno(errno, tfn); - Free(tfn); + lib3270_free(tfn); return False; } - Free(tfn); + lib3270_free(tfn); (void) SETLINEBUF(screentracef); #if !defined(_WIN32) (void) fcntl(fileno(screentracef), F_SETFD, 1); @@ -941,7 +941,7 @@ void toggle_screenTrace(H3270 *session, struct toggle *t unused, LIB3270_TOGGLE_ if (tt == TT_INITIAL || tt == TT_ACTION) { (void) screentrace_cb(NewString(tracefile)); if (tracefile_buf != NULL) - Free(tracefile_buf); + lib3270_free(tracefile_buf); return; } #if defined(X3270_DISPLAY) @@ -965,7 +965,7 @@ void toggle_screenTrace(H3270 *session, struct toggle *t unused, LIB3270_TOGGLE_ } if (tracefile_buf != NULL) - Free(tracefile_buf); + lib3270_free(tracefile_buf); } */ diff --git a/utf8.c b/utf8.c index 44a6f55..44a691b 100644 --- a/utf8.c +++ b/utf8.c @@ -432,7 +432,7 @@ utf8_set_display_charsets(char *cslist, char *csname) } if (tok == CN) { popup_an_error(NULL,"Invalid displayCharset specification"); - Free(dup); + lib3270_free(dup); return False; } @@ -444,11 +444,11 @@ utf8_set_display_charsets(char *cslist, char *csname) if (dcs[i] == CN) { popup_an_error(NULL,"Unknown displayCharset specification '%s'", csname); - Free(dup); + lib3270_free(dup); return False; } utf8_ix = i; - Free(dup); + lib3270_free(dup); return True; } */ diff --git a/util.c b/util.c index 0a54123..d3a7111 100644 --- a/util.c +++ b/util.c @@ -54,6 +54,10 @@ #include #endif // _WIN32 +#ifdef HAVE_MALLOC_H + #include +#endif + #ifndef ANDROID #include #endif // !ANDROID @@ -177,7 +181,7 @@ char * xs_vsprintf(const char *fmt, va_list args) nc = vsprintf(buf, fmt, args); if (nc > sizeof(buf)) Error(NULL,"Internal buffer overflow"); - r = Malloc(nc + 1); + r = lib3270_malloc(nc + 1); return strcpy(r, buf); #endif /*]*/ } @@ -210,7 +214,7 @@ xs_warning(const char *fmt, ...) r = xs_vsprintf(fmt, args); va_end(args); Warning(NULL,r); - Free(r); + lib3270_free(r); } void @@ -223,7 +227,7 @@ xs_error(const char *fmt, ...) r = xs_vsprintf(fmt, args); va_end(args); Error(NULL,r); - Free(r); + lib3270_free(r); } /* Prettyprinter for strings with unprintable data. */ @@ -406,11 +410,11 @@ split_dbcs_resource(const char *value, char sep, char **part1, char **part2) if (f_end == f_start) { if (c == sep) { if (*part1) { - Free(*part1); + lib3270_free(*part1); *part1 = NULL; } if (*part2) { - Free(*part2); + lib3270_free(*part2); *part2 = NULL; } return -1; @@ -427,7 +431,7 @@ split_dbcs_resource(const char *value, char sep, char **part1, char **part2) default: return 3; } - *rp = Malloc(f_end - f_start + 1); + *rp = lib3270_malloc(f_end - f_start + 1); strncpy(*rp, f_start, f_end - f_start); (*rp)[f_end - f_start] = '\0'; f_end = CN; @@ -539,7 +543,7 @@ var_subst(const char *s) return NewString(s); o_len = strlen(s) + 1; - ob = Malloc(o_len); + ob = lib3270_malloc(o_len); o = ob; # define LBR '{' # define RBR '}' @@ -604,7 +608,7 @@ var_subst(const char *s) state = VS_BASE; continue; /* rescan */ } - vn = Malloc(vn_len + 1); + vn = lib3270_malloc(vn_len + 1); (void) strncpy(vn, vn_start, vn_len); vn[vn_len] = '\0'; @@ -625,7 +629,7 @@ var_subst(const char *s) } #endif // !ANDROID - Free(vn); + lib3270_free(vn); if (state == VS_VNB) { state = VS_BASE; break; @@ -670,7 +674,7 @@ tilde_subst(const char *s) if (slash) { int len = slash - s; - mname = Malloc(len + 1); + mname = lib3270_malloc(len + 1); (void) strncpy(mname, s, len); mname[len] = '\0'; name = mname; @@ -687,13 +691,13 @@ tilde_subst(const char *s) p = getpwnam(name + 1); /* Free any temporary copy. */ - Free(mname); + lib3270_free(mname); /* Substitute and return. */ if (p == (struct passwd *)NULL) r = NewString(s); else { - r = Malloc(strlen(p->pw_dir) + strlen(rest) + 1); + r = lib3270_malloc(strlen(p->pw_dir) + strlen(rest) + 1); (void) strcpy(r, p->pw_dir); (void) strcat(r, rest); } @@ -716,7 +720,7 @@ do_subst(const char *s, Boolean do_vars, Boolean do_tilde) char *u; u = tilde_subst(t); - Free(t); + lib3270_free(t); return u; } #endif /*]*/ @@ -871,7 +875,7 @@ rpf(rpf_t *r, char *fmt, ...) void rpf_free(rpf_t *r) { - Free(r->buf); + lib3270_free(r->buf); r->buf = NULL; r->alloc_len = 0; r->cur_len = 0; -- libgit2 0.21.2