mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-15 10:00:51 -04:00
JSON API avoid capturing shared_ptr in lambda
use weak_ptr as capture shared_ptr could cause circular ref counting
This commit is contained in:
parent
954644ef57
commit
f2aa2aa543
2 changed files with 43 additions and 35 deletions
|
@ -1,20 +1,22 @@
|
||||||
/*
|
/*******************************************************************************
|
||||||
* RetroShare JSON API
|
* RetroShare JSON API *
|
||||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
* *
|
||||||
*
|
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* *
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
* it under the terms of the GNU Affero General Public License as *
|
||||||
* License, or (at your option) any later version.
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
*
|
* License, or (at your option) any later version. *
|
||||||
* This program is distributed in the hope that it will be useful,
|
* *
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* This program is distributed in the hope that it will be useful, *
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
* GNU Affero General Public License for more details.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
*
|
* GNU Affero General Public License for more details. *
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* *
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* You should have received a copy of the GNU Affero General Public License *
|
||||||
*/
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
registerHandler("$%apiPath%$",
|
registerHandler("$%apiPath%$",
|
||||||
[$%captureVars%$](const std::shared_ptr<rb::Session> session)
|
[$%captureVars%$](const std::shared_ptr<rb::Session> session)
|
||||||
|
@ -41,8 +43,12 @@ $%paramsDeclaration%$
|
||||||
|
|
||||||
$%inputParamsDeserialization%$
|
$%inputParamsDeserialization%$
|
||||||
|
|
||||||
$%callbackName%$ = [session]($%callbackParams%$)
|
const std::weak_ptr<rb::Session> weakSession(session);
|
||||||
|
$%callbackName%$ = [weakSession]($%callbackParams%$)
|
||||||
{
|
{
|
||||||
|
auto session = weakSession.lock();
|
||||||
|
if(!session || session->is_closed()) return;
|
||||||
|
|
||||||
$%callbackParamsSerialization%$
|
$%callbackParamsSerialization%$
|
||||||
|
|
||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
/*
|
/*******************************************************************************
|
||||||
* RetroShare JSON API
|
* RetroShare JSON API *
|
||||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
* *
|
||||||
*
|
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* *
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* This program is free software: you can redistribute it and/or modify *
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
* it under the terms of the GNU Affero General Public License as *
|
||||||
* License, or (at your option) any later version.
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
*
|
* License, or (at your option) any later version. *
|
||||||
* This program is distributed in the hope that it will be useful,
|
* *
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* This program is distributed in the hope that it will be useful, *
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
* GNU Affero General Public License for more details.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
*
|
* GNU Affero General Public License for more details. *
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* *
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* You should have received a copy of the GNU Affero General Public License *
|
||||||
*/
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
registerHandler("$%apiPath%$",
|
registerHandler("$%apiPath%$",
|
||||||
[$%captureVars%$](const std::shared_ptr<rb::Session> session)
|
[$%captureVars%$](const std::shared_ptr<rb::Session> session)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue