nmbd_winsserver: don't leak state_path onto talloc tos
authorDavid Disseldorp <ddiss@samba.org>
Sun, 2 Nov 2014 19:21:26 +0000 (20:21 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 3 Nov 2014 22:46:04 +0000 (23:46 +0100)
Also check for allocation failures.

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/nmbd/nmbd_winsserver.c

index e09d1a0..a56ff45 100644 (file)
@@ -594,14 +594,22 @@ bool initialise_wins(void)
        time_t time_now = time(NULL);
        XFILE *fp;
        char line[1024];
+       char *db_path;
+       char *list_path;
 
        if(!lp_we_are_a_wins_server()) {
                return True;
        }
 
+       db_path = state_path("wins.tdb");
+       if (db_path == NULL) {
+               return false;
+       }
+
        /* Open the wins.tdb. */
-       wins_tdb = tdb_open_log(state_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
+       wins_tdb = tdb_open_log(db_path, 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                        O_CREAT|O_RDWR, 0600);
+       TALLOC_FREE(db_path);
        if (!wins_tdb) {
                DEBUG(0,("initialise_wins: failed to open wins.tdb. Error was %s\n",
                        strerror(errno) ));
@@ -612,7 +620,15 @@ bool initialise_wins(void)
 
        add_samba_names_to_subnet(wins_server_subnet);
 
-       if((fp = x_fopen(state_path(WINS_LIST),O_RDONLY,0)) == NULL) {
+       list_path = state_path(WINS_LIST);
+       if (list_path == NULL) {
+               tdb_close(wins_tdb);
+               return false;
+       }
+
+       fp = x_fopen(list_path, O_RDONLY, 0);
+       TALLOC_FREE(list_path);
+       if (fp == NULL) {
                DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
                        WINS_LIST, strerror(errno) ));
                return True;