smbstatus: check for lock_path talloc failures
authorDavid Disseldorp <ddiss@samba.org>
Sun, 2 Nov 2014 19:21:49 +0000 (20:21 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 4 Nov 2014 01:07:35 +0000 (02:07 +0100)
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Nov  4 02:07:35 CET 2014 on sn-devel-104

source3/utils/status.c

index b58981329b99b2c0a87e613e51fcca35fa51b5b7..936e87b7425121da540f0379c00f488ef0476d81 100644 (file)
@@ -365,6 +365,7 @@ int main(int argc, const char *argv[])
        TALLOC_CTX *frame = talloc_stackframe();
        int ret = 0;
        struct messaging_context *msg_ctx;
+       char *db_path;
 
        sec_init();
        load_case_tables();
@@ -486,7 +487,14 @@ int main(int argc, const char *argv[])
 
        if ( show_shares ) {
                if (verbose) {
-                       d_printf("Opened %s\n", lock_path("connections.tdb"));
+                       db_path = lock_path("connections.tdb");
+                       if (db_path == NULL) {
+                               d_printf("Out of memory - exiting\n");
+                               ret = -1;
+                               goto done;
+                       }
+                       d_printf("Opened %s\n", db_path);
+                       TALLOC_FREE(db_path);
                }
 
                if (brief) {
@@ -508,18 +516,27 @@ int main(int argc, const char *argv[])
        if ( show_locks ) {
                int result;
                struct db_context *db;
-               db = db_open(NULL, lock_path("locking.tdb"), 0,
+
+               db_path = lock_path("locking.tdb");
+               if (db_path == NULL) {
+                       d_printf("Out of memory - exiting\n");
+                       ret = -1;
+                       goto done;
+               }
+
+               db = db_open(NULL, db_path, 0,
                             TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
                             DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
 
                if (!db) {
-                       d_printf("%s not initialised\n",
-                                lock_path("locking.tdb"));
+                       d_printf("%s not initialised\n", db_path);
                        d_printf("This is normal if an SMB client has never "
                                 "connected to your server.\n");
+                       TALLOC_FREE(db_path);
                        exit(0);
                } else {
                        TALLOC_FREE(db);
+                       TALLOC_FREE(db_path);
                }
 
                if (!locking_init_readonly()) {