add NT_STATUS_HAVE_NO_MEMORY_AND_FREE()
authorAndrew Tridgell <tridge@samba.org>
Tue, 2 Jun 2009 07:25:47 +0000 (17:25 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 4 Jun 2009 04:10:10 +0000 (14:10 +1000)
In many places we use NT_STATUS_HAVE_NO_MEMORY() to auto-return when a
memory allocation fails. In quite a few places where we use this, we
end up leaving a tmp_ctx behind, which creates a memory leak.

This macro takes a memory context to free when returning the error

libcli/util/ntstatus.h

index a97ef5337e20480f489e04bd00f0ca69e21fc708..dc1fcc41a4fc8146f2e82cfd43a8028013373c8c 100644 (file)
@@ -651,6 +651,15 @@ extern bool ntstatus_check_dos_mapping;
        }\
 } while (0)
 
+/* This varient is for when you want to free a local
+   temporary memory context in the error path */
+#define NT_STATUS_HAVE_NO_MEMORY_AND_FREE(x, ctx) do { \
+       if (!(x)) {\
+               talloc_free(ctx); \
+               return NT_STATUS_NO_MEMORY;\
+       }\
+} while (0)
+
 #define NT_STATUS_IS_OK_RETURN(x) do { \
        if (NT_STATUS_IS_OK(x)) {\
                return x;\