PengZheng commented on code in PR #851:
URL: https://github.com/apache/celix/pull/851#discussion_r4509271710
##########
bundles/http_admin/http_admin/src/http_admin.c:
##########
@@ -173,6 +194,51 @@ void http_admin_removeHttpService(void *handle, void *svc
CELIX_UNUSED, const ce
}
}
+static int httpAdmin_readRequestBody(struct mg_connection* connection, long
long contentLength, size_t maxRequestBodySize, char** bufferOut, size_t*
bytesReadOut, const char** errorMsgOut) {
+ celix_autofree char* buffer = NULL;
+ size_t totalBytesRead = 0;
+ *errorMsgOut = NULL;
+ if (contentLength > 0 && (size_t)contentLength > maxRequestBodySize) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_BODY_TOO_LARGE_MSG;
+ return 413;
+ }
+ if (contentLength != 0) {
+ size_t memSize = 0;
+ celix_autoptr(FILE) stream = open_memstream(&buffer, &memSize);
+ if (stream == NULL) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_INSUFFICIENT_MEM_MSG;
+ return 500;
+ }
+
+ char chunk[CELIX_HTTP_ADMIN_READ_CHUNK_SIZE];
+ while (contentLength < 0 || totalBytesRead < (size_t)contentLength) {
+ int read = mg_read(connection, chunk, sizeof(chunk));
+ if (read == 0) {
+ break; //EOF
+ } else if (read < 0) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_READ_ERROR_MSG;
+ return 400;
+ }
+ if (totalBytesRead + (size_t)read > maxRequestBodySize) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_BODY_TOO_LARGE_MSG;
+ return 413;
+ }
+ if (fwrite(chunk, 1, (size_t)read, stream) != (size_t)read) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_INSUFFICIENT_MEM_MSG;
+ return 500;
+ }
+ totalBytesRead += (size_t)read;
+ }
+ if (contentLength > 0 && totalBytesRead < (size_t)contentLength) {
Review Comment:
If `fclose(celix_streal_ptr(stream))` before this, could we replace
`memSize` by `totalBytesRead` so that we can also drop `totalBytesRead +=
(size_t)read`? Of cource we need to `fflush` the stream after `fwrite` to get
`totalBytesRead` updated.
##########
bundles/shell/remote_shell/src/remote_shell.c:
##########
@@ -140,7 +157,7 @@ celix_status_t remoteShell_stopConnections(remote_shell_pt
instance) {
for (i = 0; i < length; i += 1) {
connection_pt connection =
celix_arrayList_get(instance->connections, i);
- connection->threadRunning = false;
+ connection_setThreadRunning(connection, false);
Review Comment:
`remoteShell_stopConnections` is only invoked when bundle stops, thus the
resources used by these threads will only be released then. If new connection
keeps coming, the overall resource usage will increase monotonically. Kind of
resource leak. @pnoltes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]