[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] RPC: patch for evrpc_free() and evrpc_unregister_rpc()



Hello all,

The following patch fixes incorrect assertions in evrpc_free():
evrpc_unregister_rpc() and evrpc_remove_hook() return 0 for success.

Also, in evrpc_unregister_rpc(), it is better to free RPC structure
at the end: evrpc_free() uses rpc->uri as "name" parameter when
calling evrpc_unregister_rpc(), then rpc->uri is freed, but we
have "registered_uri = evrpc_construct_uri(name)". So at this time
"name" is invalid.

Best regards,

Christophe


diff -ur libevent-2.0.10-stable/evrpc.c libevent-2.0.10-patch/evrpc.c
--- libevent-2.0.10-stable/evrpc.c    2011-02-25 16:25:50.466781289 +0100
+++ libevent-2.0.10-patch/evrpc.c    2011-02-28 10:46:19.854280129 +0100
@@ -98,7 +98,7 @@

    while ((rpc = TAILQ_FIRST(&base->registered_rpcs)) != NULL) {
        r = evrpc_unregister_rpc(base, rpc->uri);
-        EVUTIL_ASSERT(r);
+        EVUTIL_ASSERT(r == 0);
    }
    while ((pause = TAILQ_FIRST(&base->paused_requests)) != NULL) {
        TAILQ_REMOVE(&base->paused_requests, pause, next);
@@ -106,11 +106,11 @@
    }
    while ((hook = TAILQ_FIRST(&base->input_hooks)) != NULL) {
        r = evrpc_remove_hook(base, EVRPC_INPUT, hook);
-        EVUTIL_ASSERT(r);
+        EVUTIL_ASSERT(r == 0);
    }
    while ((hook = TAILQ_FIRST(&base->output_hooks)) != NULL) {
        r = evrpc_remove_hook(base, EVRPC_OUTPUT, hook);
-        EVUTIL_ASSERT(r);
+        EVUTIL_ASSERT(r == 0);
    }
    mm_free(base);
}
@@ -263,9 +263,6 @@
    }
    TAILQ_REMOVE(&base->registered_rpcs, rpc, next);

-    mm_free((char *)rpc->uri);
-    mm_free(rpc);
-
    registered_uri = evrpc_construct_uri(name);

    /* remove the http server callback */
@@ -273,6 +270,9 @@
    EVUTIL_ASSERT(r == 0);

    mm_free(registered_uri);
+
+    mm_free((char *)rpc->uri);
+    mm_free(rpc);
    return (0);
}


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.