Permalink
Browse files

TS-567 Fix some obvious misuses of free()

git-svn-id: https://svn.apache.org/repos/asf/trafficserver/traffic/trunk@1166474 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent c8d6ff3 commit ec9310706f2d4304a41595b33130fc9a8cf4acc0 @zwoop zwoop committed Sep 7, 2011
@@ -101,11 +101,9 @@ remap_entry::~remap_entry()
int i;
if (argc && argv) {
- for (i = 0; i < argc; i++) {
- if (argv[i])
- free(argv[i]);
- }
- free(argv);
+ for (i = 0; i < argc; i++)
+ ats_free(argv[i]);
+ ats_free(argv);
}
}
@@ -330,7 +330,7 @@ _zorch_file(void *arg)
break;
info->fsize += amount;
}
- free(vals);
+ ats_free(vals);
}
delete info;
ink_atomic_increment((int *) &nzorchers, -1);
@@ -198,7 +198,7 @@ SimpleTokenizer(char *s, char delimiter = ' ', int mode = 0, char escape = '\\')
void _clearData()
{
if (_data && !(_mode & OVERWRITE_INPUT_STRING)) {
- free(_data);
+ ats_free(_data);
}
}
View
@@ -92,7 +92,8 @@ size_t CacheIdBox::getSize() const { return m_size; }
CacheIdBox&
CacheIdBox::require(size_t n) {
if (m_cap < n) {
- if (m_base && m_cap) free(m_base);
+ if (m_base && m_cap)
+ ats_free(m_base);
m_base = static_cast<CacheIdElt*>(ats_malloc(n));
m_cap = n;
}
@@ -1536,11 +1537,10 @@ detail::Assignment::fill(cache::GroupData& group, uint32_t addr) {
// we don't have to do space checks when those get filled out.
// The mask assignment is more difficult. We just guess generously and
// try to recover if we go over.
- size_t size = RouterAssignListElt::calcSize(n_routers)
- + HashAssignElt::calcSize(n_caches)
- + 4096;
+ size_t size = RouterAssignListElt::calcSize(n_routers) + HashAssignElt::calcSize(n_caches) + 4096;
+
if (m_buffer.getSize() < size) {
- free(m_buffer.getBase());
+ ats_free(m_buffer.getBase());
m_buffer.set(ats_malloc(size), size);
}
m_buffer.reset();
@@ -247,8 +247,10 @@ Cmd_Config(ClientData clientData, Tcl_Interp * interp, int argc, const char *arg
cmdinfo[i] = 0;
Cli_Printf("Following are the available config commands\n");
Cli_Printf(cmdinfo + strlen("config "));
- free(cmdinfo);
- free(temp);
+
+ ats_free(cmdinfo);
+ ats_free(temp);
+
return CLI_OK;
}
View
@@ -92,8 +92,10 @@ Cmd_Show(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[
cmdinfo[i] = 0;
Cli_Printf("Following are the available show commands\n");
Cli_Printf(cmdinfo + strlen("show "));
- free(cmdinfo);
- free(temp);
+
+ ats_free(cmdinfo);
+ ats_free(temp);
+
return 0;
}
@@ -129,12 +129,12 @@ cliParseArgument(int argc, const char **argv, cli_CommandInfo * commandInfo)
parsedArgTable[i].arg_int = CLI_DEFAULT_INT_OR_FLOAT_VALUE;
if (parsedArgTable[i].data && (parsedArgTable[i].data != (char *) NULL)) {
- free(parsedArgTable[i].data);
+ ats_free(parsedArgTable[i].data);
parsedArgTable[i].data = (char *) NULL;
}
if (parsedArgTable[i].arg_string && parsedArgTable[i].arg_string != (char *) NULL) {
- free(parsedArgTable[i].arg_string);
+ ats_free(parsedArgTable[i].arg_string);
parsedArgTable[i].arg_string = (char *) NULL;
}
}
@@ -178,7 +178,7 @@ cliParseArgument(int argc, const char **argv, cli_CommandInfo * commandInfo)
if (prevMatchPtr != NULL && prevPtr == prevMatchPtr) {
if (prevMatchPtr->type == CLI_ARGV_OPTION_NAME_VALUE) {
if (prev_parsedInfoPtr->arg_string) {
- free(prev_parsedInfoPtr->arg_string);
+ ats_free(prev_parsedInfoPtr->arg_string);
prev_parsedInfoPtr->arg_string = NULL;
}
}
@@ -1331,7 +1331,7 @@ Net_SetEncryptedRootPassword(char *password)
strtok_r(buf, ":", &remainingTokens);
strtok_r(NULL, ":", &remainingTokens);
fprintf(tmp, "root:%s:%s", password, remainingTokens);
- free(buf);
+ ats_free(buf);
}
}
NOWARN_UNUSED_RETURN(fgets(buffer, 1024, fp));
@@ -351,7 +351,7 @@ void TextMod::print(FILE* f) const {
TextMod::TextMod() : text(0,0) {}
TextMod::~TextMod() {
- if (text.data()) free(text.data());
+ free(text.data());
}
// ----------
View
@@ -309,10 +309,10 @@ CoreUtils::read_from_core(intptr_t vaddr, intptr_t bytes, char *buf)
*buf++ = getc(fp);
}
buf -= bytes;*/
- free(frameoff);
+ ats_free(frameoff);
return bytes;
}
- free(frameoff);
+ ats_free(frameoff);
}
} else
return -1;
@@ -360,7 +360,7 @@ CoreUtils::get_base_frame(intptr_t threadId, core_stack_state * coress)
framep = regs.rw_in[6];
coress->framep = framep;
}
- free(frameoff);
+ ats_free(frameoff);
} else {
printf("Failed to seek to top of the stack\n");
}
@@ -406,7 +406,7 @@ CoreUtils::get_next_frame(core_stack_state * coress)
coress->framep = framep;
}
}
- free(frameoff);
+ ats_free(frameoff);
}
}
return 1;
@@ -474,7 +474,7 @@ CoreUtils::get_base_frame(intptr_t framep, core_stack_state *coress)
}
}
}
- free(frameoff);
+ ats_free(frameoff);
}
} else {
printf("Failed to seek to top of the stack\n");
@@ -504,7 +504,7 @@ CoreUtils::get_next_frame(core_stack_state * coress)
if (fread(frameoff, 4, 1, fp) == 1) {
coress->framep = (intptr_t) *frameoff;
if (*frameoff == NULL) {
- free(frameoff);
+ ats_free(frameoff);
return 0;
}
if (fread(frameoff, 4, 1, fp) == 1) {
@@ -516,7 +516,7 @@ CoreUtils::get_next_frame(core_stack_state * coress)
}
}
}
- free(frameoff);
+ ats_free(frameoff);
}
return 1;
}
@@ -631,7 +631,7 @@ CoreUtils::process_HttpSM(HttpSM * core_ptr)
if (read_from_core((intptr_t) core_ptr, sizeof(HttpSM), (char *) http_sm) < 0) {
// This is not 64-bit correct ... /leif
printf("ERROR: Failed to read httpSM @ 0x%p from core\n", core_ptr);
- free(http_sm);
+ ats_free(http_sm);
return;
}
@@ -673,7 +673,7 @@ CoreUtils::process_HttpSM(HttpSM * core_ptr)
}
}
- free(http_sm);
+ ats_free(http_sm);
} else
printf("process_HttpSM : last_seen_http_sm == core_ptr\n");
}
@@ -806,7 +806,7 @@ CoreUtils::load_http_hdr(HTTPHdr * core_hdr, HTTPHdr * live_hdr)
char *free_start = (char *) (((HdrStrHeap *) str_hdr)->m_free_start);
int nto_copy = abs((char *) copy_start - free_start);
- free(str_hdr);
+ ats_free(str_hdr);
#if defined(__GNUC__)
char rw_heap[sizeof(char) * nto_copy];
#else
@@ -986,7 +986,7 @@ CoreUtils::process_EThread(EThread * eth_test)
// printf(" NetHandler: 0x%x\n\n", (int) loaded_eth->netHandler);
}
- free(buf);
+ ats_free(buf);
}
static void
@@ -1020,7 +1020,7 @@ CoreUtils::process_NetVC(UnixNetVConnection * nvc_test)
print_netstate(&loaded_nvc->write);
}
- free(buf);
+ ats_free(buf);
}
@@ -1194,7 +1194,7 @@ process_core(char *fname)
size -= len;
}
}
- free(nhdr);
+ ats_free(nhdr);
}
}
}
@@ -1352,7 +1352,7 @@ process_core(char *fname)
size -= len;
}
}
- free(nhdr);
+ ats_free(nhdr);
}
}
}
@@ -459,9 +459,8 @@ synclient_txn_delete(ClientTxn * txn)
TSActionCancel(txn->connect_action);
txn->connect_action = NULL;
}
- if (txn->request) {
- free(txn->request);
- }
+
+ ats_free(txn->request);
txn->magic = MAGIC_DEAD;
TSfree(txn);
return 1;
@@ -724,7 +724,7 @@ ParentRecord::DefaultInit(char *val)
//
// Returns NULL if everything is OK
// Otherwise, returns an error string that the caller MUST
-// DEALLOCATE with free()
+// DEALLOCATE with ats_free()
//
char *
ParentRecord::Init(matcher_line * line_info)
@@ -312,7 +312,7 @@ main(int argc, char *argv[])
if ((bind(fd, (struct sockaddr *) &saddr, sizeof(saddr))) < 0) {
perror("bind(udp_fd)");
- free(pkt_buf);
+ ats_free(pkt_buf);
return 0;
}
@@ -331,5 +331,5 @@ main(int argc, char *argv[])
stream_hash_table->deleteStaleStreams(now);
}
- free(pkt_buf);
+ ats_free(pkt_buf);
}
@@ -101,13 +101,13 @@ process_http_hdr_impl(HdrHeapObjImpl * obj, int offset)
printf(" is a request hdr\n");
s = load_string(hhdr->u.req.m_ptr_method, hhdr->u.req.m_len_method, offset);
printf(" method: %s\n", s);
- free(s);
+ ats_free(s);
} else if (hhdr->m_polarity == HTTP_TYPE_RESPONSE) {
printf(" is a response hdr\n");
printf(" status code: %d\n", (int) hhdr->u.resp.m_status);
s = load_string(hhdr->u.resp.m_ptr_reason, hhdr->u.resp.m_len_reason, offset);
printf(" method: %s\n", s);
- free(s);
+ ats_free(s);
}
}
@@ -133,8 +133,8 @@ process_mime_block_impl(MIMEFieldBlockImpl * mblock, int offset)
}
v = load_string(f->m_ptr_value, f->m_len_value, offset);
printf(" (%d) %s: %s\n", i, n, v);
- free(n);
- free(v);
+ ats_free(n);
+ ats_free(v);
}
}
@@ -38,7 +38,7 @@ HttpMessageBody::StatusCodeName(HTTPStatus status_code)
(using malloc), and places the result body in the buffer. The body
will be NUL terminated.
- The caller must free() the returned object when done.
+ The caller must ats_free() the returned object when done.
The reason string allows you to override the default reason phrase for
the status code. If it is NULL, the default is used. If format is NULL

0 comments on commit ec93107

Please sign in to comment.