Skip to content

Commit

Permalink
perf: lessen memory alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed May 6, 2021
1 parent a6a558f commit 99f4312
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=UA2F
PKG_VERSION:=3.3
PKG_VERSION:=3.4

PKG_RELEASE:=7
PKG_RELEASE:=8


PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
Expand Down
14 changes: 5 additions & 9 deletions src/ua2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ static int debugflag = 0;
static int debugflag2 = 0;
static char timestr[60];

char *str = NULL;

static struct ipset *Pipset;

static char *time2str(int sec) {
Expand Down Expand Up @@ -161,7 +163,6 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
unsigned int tcppklen;
unsigned int uaoffset = 0;
unsigned int ualength = 0;
char *str = NULL;
void *payload;
uint32_t mark = 0;
bool noUA = false;
Expand Down Expand Up @@ -277,12 +278,6 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
debugflag++; //flag7

if (uaoffset && ualength) {
str = malloc(ualength);
if (!str) {
pktb_free(pktb);
return MNL_CB_ERROR;
}
memset(str, 'F', ualength);

if (uaoffset >= tcppklen) {
syslog(LOG_ERR, "Offset overflow");
Expand All @@ -294,10 +289,8 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
}
if (nfq_tcp_mangle_ipv4(pktb, uaoffset, ualength, str, ualength) == 1) {
UAcount++; //记录修改包的数量
free(str);//用完就丢
noUA = false;
} else {
free(str);
pktb_free(pktb);
return MNL_CB_ERROR;
}
Expand Down Expand Up @@ -418,6 +411,9 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}

str = malloc(sizeof_buf);
memset(str, 'F', sizeof_buf);

nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_number);
nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);

Expand Down

0 comments on commit 99f4312

Please sign in to comment.