yihui 从208行PROTECT以后,立即执行if分支,两个分支中一个有UNPROTECT,另外一个没有;
程序没有问题,可能自动判读用的工具没有上下文关联功能;
从R源代码包的 R-4.0.2/modules/internet/Rhttpd.c 看,208行的PROTECT() 后面的一句判断 if (result) 是不必要的,默认系统分配不会返回NULL,always TRUE
In Rdefines.h
#define NEW_RAW(n) Rf_allocVector(RAWSXP,n)
In Rhttpd.c
static SEXP parse_request_body(httpd_conn_t *c) {
if (!c || !c->body) return R_NilValue;
if (c->attr & CONTENT_FORM_UENC) { /* URL encoded form - return parsed form */
c->body[c->content_length] = 0; /* the body is guaranteed to have an extra byte for the termination */
return parse_query(c->body);
} else { /* something else - pass it as a raw vector */
SEXP res = PROTECT(Rf_allocVector(RAWSXP, c->content_length));
if (c->content_length)
memcpy(RAW(res), c->body, c->content_length);
if (c->content_type) { /* attach the content type so it can be interpreted */
if (!R_ContentTypeName) R_ContentTypeName = install("content-type");
setAttrib(res, R_ContentTypeName, mkString(c->content_type));
}
UNPROTECT(1);
return res;
}
}
仅供参考