We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Report
nlohmann::json::parse exhaust memory inside cgo
nlohmann::json::parse
Code :
parse.hpp
#ifndef PARSE_DEMO_H_ #define PARSE_DEMO_H_ #ifdef __cplusplus extern "C" { #endif void parse(char* value); #ifdef __cplusplus } #endif #endif
parse.cpp
#include "parse.hpp" #include "json.hpp" extern "C" void parse(char* value) { try { nlohmann::json::parse(value); } catch (std::exception&) {} }
leaker.go
package main import ( "unsafe" ) // #include <stdlib.h> // #include "parse.hpp" // #cgo LDFLAGS: -lparse -lstdc++ import "C" func main() { input := "{\"hello\": \"world\"}"; for ;; { cinput := C.CString(input); defer C.free(unsafe.Pointer(cinput)) C.parse(cinput) } }
run.sh
#!/bin/bash set -eo pipefail g++ -g -c -std=gnu++17 ./parse.cpp -o parse.o ar -s -r libparse.a parse.o rm parse.o CGO_LDFLAGS=-L"$PWD" go run leaker.go
Dockerfile
FROM ubuntu:17.10 RUN apt-get update --yes && \ apt-get install \ curl \ g++ \ --yes ENV GO_VERSION=1.9 \ GO_SHA256=d70eadefce8e160638a9a6db97f7192d8463069ab33138893ad3bf31b0650a79 RUN curl https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz -o /golang.tar.gz && \ echo "${GO_SHA256} /golang.tar.gz" | sha256sum -c - && \ tar -xzf /golang.tar.gz && \ cd /usr/local/bin && ln -s /go/bin/* . && \ go version && \ rm /golang.tar.gz RUN mkdir -p /usr/local/demo/ COPY /* /usr/local/demo/ WORKDIR /usr/local/demo
Constant memory usage
Increasing memory usage
g++ (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
develop
I used the latest release version to date
The text was updated successfully, but these errors were encountered:
Error unrelated to the nlohmann library
Sorry, something went wrong.
Thanks for reporting back!
No branches or pull requests
Bug Report
nlohmann::json::parse
exhaust memory inside cgoCode :
parse.hpp
parse.cpp
leaker.go
run.sh
Dockerfile
Constant memory usage
Increasing memory usage
g++ (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
develop
branch?I used the latest release version to date
The text was updated successfully, but these errors were encountered: