[FIX] Fix memory issue when creating a configuration

This commit is contained in:
lda 2023-12-03 16:41:45 +01:00
parent a7d6dfc870
commit 39ef050109
Signed by: lda
GPG key ID: 6898757653ABE3E6

View file

@ -136,6 +136,8 @@ ConfigCreateDefault(Db * db)
config.registration = 0;
config.federation = 1;
config.serverName = Malloc(HOST_NAME_MAX + 1);
memset(config.serverName, 0, HOST_NAME_MAX + 1);
gethostname(config.serverName, HOST_NAME_MAX);
len = strlen(config.serverName) + 10;
config.baseUrl = Malloc(len);
@ -151,13 +153,6 @@ ConfigCreateDefault(Db * db)
listener->tls.cert = NULL;
ArrayAdd(config.listen, listener);
config.serverName = Malloc(HOST_NAME_MAX + 1);
/* TODO: Don't set that field(it has to because otherwise j2s will add
* a NULL byte it seems.) */
config.identityServer = StrDuplicate("");
json = ConfigToJson(&config);
ref = DbCreate(db, 1, "config");