[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] Fixed some memory leaks and did some style changes.
commit 1c94e6df95fd8808bca3722fdcc9eba25d3bb0fb
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date: Sun May 29 23:28:53 2011 +0200
Fixed some memory leaks and did some style changes.
---
src/main.c | 29 ++++++++++++++++++-----------
src/network.c | 12 +-----------
src/protocol.c | 26 +++++++++++++++-----------
src/protocol.h | 2 ++
src/protocols/obfs2.c | 1 +
5 files changed, 37 insertions(+), 33 deletions(-)
diff --git a/src/main.c b/src/main.c
index 68ea424..dffe210 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,11 +19,13 @@
#define __attribute__(x)
#endif
-static void usage(void) __attribute__((noreturn));
-
+/* The character that seperates multiple listeners in the cli */
#define SEPERATOR "+"
+/* Totally arbitrary. */
#define MAXPROTOCOLS 20
+static void usage(void) __attribute__((noreturn));
+
/* protocol.c */
extern char *supported_protocols[];
extern int n_supported_protocols;
@@ -85,6 +87,8 @@ is_supported_protocol(const char *name) {
return 0;
}
+#define STUPID_BEAUTIFIER "===========================\n"
+
int
main(int argc, const char **argv)
{
@@ -215,10 +219,11 @@ main(int argc, const char **argv)
listener_t *temp_listener;
int n_listeners=0;
for (h=0;h<actual_protocols;h++) {
+
if (n_protocols > 1) {
- printf("===========================\n"
- "Spawning listener %d!\n"
- "===========================\n", h+1);
+ dbg((STUPID_BEAUTIFIER
+ "Spawning listener %d!\n"
+ STUPID_BEAUTIFIER, h+1));
}
temp_listener = listener_new(base, n_options_array[h], protocol_options[h]);
@@ -232,18 +237,18 @@ main(int argc, const char **argv)
continue;
}
- printf("Succesfully created listener.\n");
+ dbg(("Succesfully created listener.\n"));
listeners[n_listeners] = temp_listener;
n_listeners++;
}
if (n_protocols > 1) {
- printf("\n===========================\n"
- "From the original %d protocols only %d were parsed from main.c. "
- "In the end only %d survived.\n\nStarting up...\n"
- "===========================\n",
- n_protocols, actual_protocols,n_listeners);
+ dbg((STUPID_BEAUTIFIER
+ "From the original %d protocols only %d were parsed from main.c. "
+ "In the end only %d survived.\n\nStarting up...\n"
+ STUPID_BEAUTIFIER,
+ n_protocols, actual_protocols,n_listeners));
}
/* run the event loop if at least a listener was created. */
@@ -258,3 +263,5 @@ main(int argc, const char **argv)
return 0;
}
+
+#undef STUPID_BEAUTIFIER
diff --git a/src/network.c b/src/network.c
index 1c4b853..3b3c2bf 100644
--- a/src/network.c
+++ b/src/network.c
@@ -71,23 +71,13 @@ listener_new(struct event_base *base,
return lsn;
}
-static void
-protocol_params_free(protocol_params_t *params)
-{
- assert(params);
-
- if (params->shared_secret)
- free(params->shared_secret);
- free(params);
-}
-
void
listener_free(listener_t *lsn)
{
if (lsn->listener)
evconnlistener_free(lsn->listener);
if (lsn->proto_params)
- protocol_params_free(lsn->proto_params);
+ proto_params_free(lsn->proto_params);
memset(lsn, 0xb0, sizeof(listener_t));
free(lsn);
}
diff --git a/src/protocol.c b/src/protocol.c
index b86bb5f..1c93150 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -43,20 +43,12 @@ proto_new(protocol_params_t *params) {
if (!proto)
return NULL;
- proto->vtable = calloc(1, sizeof(struct protocol_vtable));
- if (!proto->vtable)
- return NULL;
-
- if (params->proto == OBFS2_PROTOCOL) {
+ if (params->proto == OBFS2_PROTOCOL)
proto->state = obfs2_new(proto, params);
- } else if (params->proto == DUMMY_PROTOCOL) {
+ else if (params->proto == DUMMY_PROTOCOL)
proto->state = dummy_new(proto, NULL);
- }
- if (proto->state)
- return proto;
- else
- return NULL;
+ return proto->state ? proto : NULL;
}
int
@@ -93,4 +85,16 @@ proto_destroy(struct protocol_t *proto) {
if (proto->vtable->destroy)
proto->vtable->destroy(proto->state);
+
+ free(proto);
+}
+
+void
+proto_params_free(protocol_params_t *params)
+{
+ assert(params);
+
+ if (params->shared_secret)
+ free(params->shared_secret);
+ free(params);
}
diff --git a/src/protocol.h b/src/protocol.h
index 0f45f22..0a7c452 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -52,6 +52,8 @@ int proto_handshake(struct protocol_t *proto, void *buf);
int proto_send(struct protocol_t *proto, void *source, void *dest);
int proto_recv(struct protocol_t *proto, void *source, void *dest);
+void proto_params_free(protocol_params_t *params);
+
typedef struct protocol_vtable {
/* Initialization function: Fills in the protocol vtable. */
diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c
index 41a97aa..115337e 100644
--- a/src/protocols/obfs2.c
+++ b/src/protocols/obfs2.c
@@ -136,6 +136,7 @@ obfs2_init(int n_options, char **options,
}
return 1;
+
err:
usage();
return -1;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits