Thanks for the change.
Tested-by: Yifeng Sun <pkusunyif...@gmail.com> Reviewed-by: Yifeng Sun <pkusunyif...@gmail.com> On Wed, Dec 13, 2017 at 10:04 AM, Ben Pfaff <b...@ovn.org> wrote: > This simplifies little bits of code here and there. > > Signed-off-by: Ben Pfaff <b...@ovn.org> > --- > lib/ovsdb-error.c | 17 +++++++++++++++++ > lib/ovsdb-error.h | 1 + > ovsdb/execution.c | 4 +--- > ovsdb/jsonrpc-server.c | 24 ++++++------------------ > 4 files changed, 25 insertions(+), 21 deletions(-) > > diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c > index 9b1af68c6ca3..a75ad36b7374 100644 > --- a/lib/ovsdb-error.c > +++ b/lib/ovsdb-error.c > @@ -203,6 +203,8 @@ ovsdb_error_clone(const struct ovsdb_error *old) > } > } > > +/* Returns 'error' converted to the <error> JSON object format described > in RFC > + * 7047. The caller must free the returned json (with json_destroy()). */ > struct json * > ovsdb_error_to_json(const struct ovsdb_error *error) > { > @@ -211,6 +213,8 @@ ovsdb_error_to_json(const struct ovsdb_error *error) > if (error->details) { > json_object_put_string(json, "details", error->details); > } > + > + /* These are RFC 7047-compliant extensions. */ > if (error->syntax) { > json_object_put_string(json, "syntax", error->syntax); > } > @@ -218,6 +222,19 @@ ovsdb_error_to_json(const struct ovsdb_error *error) > json_object_put_string(json, "io-error", > ovs_retval_to_string(error->errno_)); > } > + > + return json; > +} > + > +/* Returns 'error' converted to the <error> JSON object format described > in RFC > + * 7047. The caller must free the returned json (with json_destroy()). > + * > + * Also, frees 'error'. */ > +struct json * > +ovsdb_error_to_json_free(struct ovsdb_error *error) > +{ > + struct json *json = ovsdb_error_to_json(error); > + ovsdb_error_destroy(error); > return json; > } > > diff --git a/lib/ovsdb-error.h b/lib/ovsdb-error.h > index ff9b889a8687..77a60e074f9c 100644 > --- a/lib/ovsdb-error.h > +++ b/lib/ovsdb-error.h > @@ -66,6 +66,7 @@ struct ovsdb_error *ovsdb_error_clone(const struct > ovsdb_error *) > char *ovsdb_error_to_string(const struct ovsdb_error *); > char *ovsdb_error_to_string_free(struct ovsdb_error *); > struct json *ovsdb_error_to_json(const struct ovsdb_error *); > +struct json *ovsdb_error_to_json_free(struct ovsdb_error *); > > const char *ovsdb_error_get_tag(const struct ovsdb_error *); > > diff --git a/ovsdb/execution.c b/ovsdb/execution.c > index 016b9c68767c..bb3befe43848 100644 > --- a/ovsdb/execution.c > +++ b/ovsdb/execution.c > @@ -120,9 +120,7 @@ ovsdb_execute(struct ovsdb *db, const struct > ovsdb_session *session, > "as first parameter"); > } > > - results = ovsdb_error_to_json(error); > - ovsdb_error_destroy(error); > - return results; > + return ovsdb_error_to_json_free(error); > } > > x.db = db; > diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c > index b94681daf671..f4a14d4fb2c2 100644 > --- a/ovsdb/jsonrpc-server.c > +++ b/ovsdb/jsonrpc-server.c > @@ -730,8 +730,8 @@ ovsdb_jsonrpc_lookup_db(const struct > ovsdb_jsonrpc_session *s, > return db; > > error: > - *replyp = jsonrpc_create_error(ovsdb_error_to_json(error), > request->id); > - ovsdb_error_destroy(error); > + *replyp = jsonrpc_create_error(ovsdb_error_to_json_free(error), > + request->id); > return NULL; > } > > @@ -781,7 +781,6 @@ ovsdb_jsonrpc_session_lock(struct > ovsdb_jsonrpc_session *s, > enum ovsdb_lock_mode mode) > { > struct ovsdb_lock_waiter *waiter; > - struct jsonrpc_msg *reply; > struct ovsdb_error *error; > struct ovsdb_session *victim; > const char *lock_name; > @@ -820,9 +819,7 @@ ovsdb_jsonrpc_session_lock(struct > ovsdb_jsonrpc_session *s, > return jsonrpc_create_reply(result, request->id); > > error: > - reply = jsonrpc_create_error(ovsdb_error_to_json(error), > request->id); > - ovsdb_error_destroy(error); > - return reply; > + return jsonrpc_create_error(ovsdb_error_to_json_free(error), > request->id); > } > > static void > @@ -857,7 +854,6 @@ ovsdb_jsonrpc_session_unlock(struct > ovsdb_jsonrpc_session *s, > struct jsonrpc_msg *request) > { > struct ovsdb_lock_waiter *waiter; > - struct jsonrpc_msg *reply; > struct ovsdb_error *error; > const char *lock_name; > > @@ -884,9 +880,7 @@ ovsdb_jsonrpc_session_unlock(struct > ovsdb_jsonrpc_session *s, > return jsonrpc_create_reply(json_object_create(), request->id); > > error: > - reply = jsonrpc_create_error(ovsdb_error_to_json(error), > request->id); > - ovsdb_error_destroy(error); > - return reply; > + return jsonrpc_create_error(ovsdb_error_to_json_free(error), > request->id); > } > > static struct jsonrpc_msg * > @@ -1361,9 +1355,7 @@ error: > ovsdb_jsonrpc_monitor_destroy(m); > } > > - json = ovsdb_error_to_json(error); > - ovsdb_error_destroy(error); > - return jsonrpc_create_error(json, request_id); > + return jsonrpc_create_error(ovsdb_error_to_json_free(error), > request_id); > } > > static struct ovsdb_error * > @@ -1406,7 +1398,6 @@ ovsdb_jsonrpc_monitor_cond_change(struct > ovsdb_jsonrpc_session *s, > struct ovsdb_jsonrpc_monitor *m; > struct json *monitor_cond_change_reqs; > struct shash_node *node; > - struct json *json; > > if (json_array(params)->n != 3) { > error = ovsdb_syntax_error(params, NULL, "invalid parameters"); > @@ -1490,10 +1481,7 @@ ovsdb_jsonrpc_monitor_cond_change(struct > ovsdb_jsonrpc_session *s, > return jsonrpc_create_reply(json_object_create(), request_id); > > error: > - > - json = ovsdb_error_to_json(error); > - ovsdb_error_destroy(error); > - return jsonrpc_create_error(json, request_id); > + return jsonrpc_create_error(ovsdb_error_to_json_free(error), > request_id); > } > > static struct jsonrpc_msg * > -- > 2.10.2 > > _______________________________________________ > dev mailing list > d...@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev > _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev