Skip to content

Commit

Permalink
Merge pull request #283 from bb111189/master
Browse files Browse the repository at this point in the history
Fix double free issue if client_connection is nullptr
  • Loading branch information
cinemast committed Oct 30, 2019
2 parents af3d9c6 + aff0e24 commit 662586e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**I am currently working on a new C++17 implementation -> [json-rpc-cxx](https://github.com/jsonrpcx/json-rpc-cxx). It is still a work in progress, but early feedback is very welcome.**
**I am currently working on a new C++17 implementation -> [json-rpc-cxx](https://github.com/jsonrpcx/json-rpc-cxx).**

Master [![Build Status](https://travis-ci.org/cinemast/libjson-rpc-cpp.png?branch=master)](https://travis-ci.org/cinemast/libjson-rpc-cpp) [![codecov](https://codecov.io/gh/cinemast/libjson-rpc-cpp/branch/master/graph/badge.svg)](https://codecov.io/gh/cinemast/libjson-rpc-cpp)
Develop [![Build Status](https://travis-ci.org/cinemast/libjson-rpc-cpp.png?branch=develop)](https://travis-ci.org/cinemast/libjson-rpc-cpp) [![codecov](https://codecov.io/gh/cinemast/libjson-rpc-cpp/branch/develop/graph/badge.svg)](https://codecov.io/gh/cinemast/libjson-rpc-cpp) |
Expand Down Expand Up @@ -146,16 +146,19 @@ This example will show the most simple way to create a rpc server and client. If
]
```

The type of a return value or parameter is defined by the literal assigned to it. In this example you can see how to specify methods and notifications.
The type of a return value or parameter is defined by the literal assigned to it. The generated stubs will will use the "returns" type to validate the response. In this example you can see how to specify methods and notifications.

### Step 2: Generate the stubs for client and server ###

Call jsonrpcstub:
```sh
jsonrpcstub spec.json --cpp-server=AbstractStubServer --cpp-client=StubClient
mkdir -p gen
mv abstractstubserver.h gen
mv stubclient.ch gen
```

This generates a serverstub and a clientstub class.
This generates an `AbstractStubServer` and a `StubClient` class and moves them to the `gen` folder.


### Step 3: implement the abstract server stub ###
Expand All @@ -170,7 +173,7 @@ In the main function the concrete server is instantiated and started. That is al
Compile the server with:

```sh
g++ main.cpp -ljsoncpp -lmicrohttpd -ljsonrpccpp-common -ljsonrpccpp-server -o sampleserver
g++ stubserver.cpp -ljsoncpp -lmicrohttpd -ljsonrpccpp-common -ljsonrpccpp-server -o sampleserver
```

### Step 4: Create the client application
Expand All @@ -182,7 +185,7 @@ See [src/examples/stubclient.cpp](src/examples/stubclient.cpp)
Compile the client with:

```sh
g++ main.cpp -ljsoncpp -lcurl -ljsonrpccpp-common -ljsonrpccpp-client -o sampleclient
g++ stubclient.cpp -ljsoncpp -lcurl -ljsonrpccpp-common -ljsonrpccpp-client -o sampleclient
```

## Contributions
Expand Down
14 changes: 14 additions & 0 deletions docker/Centos7.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM centos:7

ENV OS=centos7
RUN yum -y install epel-release
RUN yum -y install jsoncpp-devel libcurl-devel hiredis-devel redis cmake3 argtable-devel gcc-c++ wget gnutls-devel git gnutls-devel libgcrypt-devel
ENV MICROHTTPD_VERSION=0.9.37
RUN wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-${MICROHTTPD_VERSION}.tar.gz && tar xvz -f libmicrohttpd-${MICROHTTPD_VERSION}.tar.gz \
&& cd libmicrohttpd-${MICROHTTPD_VERSION} && ./configure && make -j$(nproc) && make install
RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake
RUN mkdir /app
COPY docker/build_test_install.sh /app
COPY . /app
RUN chmod a+x /app/build_test_install.sh
RUN cd /app && ./build_test_install.sh
2 changes: 1 addition & 1 deletion docker/build_test_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -evu

PREFIX=/usr/local

if [ "$OS" == "arch" ] || [ "$OS" == "fedora" ]
if [ "$OS" == "arch" ] || [ "$OS" == "fedora" ] || [ "$OS" == "centos7" ]
then
PREFIX=/usr
fi
Expand Down
6 changes: 5 additions & 1 deletion src/jsonrpccpp/server/connectors/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ int HttpServer::callback(void *cls, MHD_Connection *connection, const char *url,
client_connection->server->SendResponse("Not allowed HTTP Method",
client_connection);
}
delete client_connection;

if (client_connection != nullptr)
{
delete client_connection;
}
*con_cls = NULL;

return MHD_YES;
Expand Down

0 comments on commit 662586e

Please sign in to comment.