Free memory returned by client functions
authorSam Thursfield <samthursfield@codethink.co.uk>
Wed, 6 Jul 2011 16:55:55 +0000 (17:55 +0100)
committerSam Thursfield <samthursfield@codethink.co.uk>
Wed, 6 Jul 2011 16:55:55 +0000 (17:55 +0100)
examples/client.c
libmoonshot/libmoonshot-dbus.c
libmoonshot/libmoonshot-msrpc.c
libmoonshot/libmoonshot.h
tests/basic.c

index 3cbfa0f..df529b7 100644 (file)
@@ -25,6 +25,14 @@ int main (int    argc,
 
     if (success) {
         printf ("Got identity: %s %s %s\n", nai, password, server_certificate_hash);
+
+        moonshot_free (nai);
+        moonshot_free (password);
+        moonshot_free (server_certificate_hash);
+        moonshot_free (ca_certificate);
+        moonshot_free (subject_name_constraint);
+        moonshot_free (subject_alt_name_constraint);
+
         return 0;
     } else {
         printf ("Error: %s\n", error->message);
index 17a7246..ca76000 100644 (file)
  * waiting for calls.
  */
 
+void moonshot_free (void *data)
+{
+    g_free (data);
+}
+
 static DBusGProxy *dbus_connect (MoonshotError **error)
 {
     DBusConnection  *connection;
index ad67f5c..8345483 100644 (file)
 #define MOONSHOT_INSTALL_PATH_KEY "Software\\Moonshot"
 
 void *__RPC_USER MIDL_user_allocate (size_t size) {
-       return malloc (size);
+    return malloc (size);
 }
 
 void __RPC_USER MIDL_user_free (void *data) {
-       free (data);
+    if (data == NULL)
+        return;
+
+    free (data);
+}
+
+void moonshot_free (void *data)
+{
+    free (data);
 }
 
 static MoonshotError *moonshot_error_new_from_status (MoonshotErrorCode code,
index d4af826..86e6a80 100644 (file)
 #ifndef __LIBMOONSHOT_H
 #define __LIBMOONSHOT_H
 
+/**
+ * moonshot_free:
+ * @pointer: pointer to be freed
+ *
+ * All the strings returned by the get_identity() functions must be
+ * freed using this function when they are no longer needed.
+ *
+ * @pointer may be %NULL, in which case no action is taken.
+ */
+void moonshot_free (void *data);
+
 typedef enum {
     MOONSHOT_ERROR_UNABLE_TO_START_SERVICE,
     MOONSHOT_ERROR_NO_IDENTITY_SELECTED,
@@ -48,6 +59,13 @@ typedef struct {
     char              *message;
 } MoonshotError;
 
+/**
+ * moonshot_error_free:
+ * @error: A #MoonshotError
+ *
+ * Releases the memory used by @error. This function must be called if
+ * a function has returned an error, once it has been reported.
+ */
 void moonshot_error_free (MoonshotError *error);
 
 /**
index 76a3174..cc9e468 100644 (file)
@@ -30,6 +30,13 @@ gpointer test_func (gpointer data)
     /*if (success)
         g_print ("Got id: %s %s\n", nai, password);*/
 
+    moonshot_free (nai);
+    moonshot_free (password);
+    moonshot_free (server_certificate_hash);
+    moonshot_free (ca_certificate);
+    moonshot_free (subject_name_constraint);
+    moonshot_free (subject_alt_name_constraint);
+
     return GINT_TO_POINTER (success);
 }