|
@@ -50,7 +50,7 @@ int users_init(void) {
|
|
|
exit(1);
|
|
exit(1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (unlikely(!(vccd_dir = malloc(PATH_MAX)))) {
|
|
|
|
|
|
|
+ if (unlikely(!(vccd_dir = amalloc(PATH_MAX)))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
exit(1);
|
|
exit(1);
|
|
@@ -73,7 +73,7 @@ int open_user_file(char *usr) {
|
|
|
char *fname;
|
|
char *fname;
|
|
|
int fdt;
|
|
int fdt;
|
|
|
|
|
|
|
|
- if (unlikely(!(fname = malloc(PATH_MAX)))) {
|
|
|
|
|
|
|
+ if (unlikely(!(fname = amalloc(PATH_MAX)))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
return -1;
|
|
return -1;
|
|
@@ -87,7 +87,7 @@ int open_user_file(char *usr) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- free(fname);
|
|
|
|
|
|
|
+ afree(fname, PATH_MAX);
|
|
|
|
|
|
|
|
return fdt;
|
|
return fdt;
|
|
|
}
|
|
}
|
|
@@ -116,13 +116,13 @@ int do_user_login(int fd, struct vcc_request *req) {
|
|
|
static const char *join_msg = "%s logged in. now there are %d users. \n";
|
|
static const char *join_msg = "%s logged in. now there are %d users. \n";
|
|
|
char *t;
|
|
char *t;
|
|
|
|
|
|
|
|
- if (unlikely(!(out = malloc(sizeof(struct vcc_request))))) {
|
|
|
|
|
|
|
+ if (unlikely(!(out = amalloc(sizeof(struct vcc_request))))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (unlikely(!(usr = malloc(sizeof(struct user))))) {
|
|
|
|
|
|
|
+ if (unlikely(!(usr = amalloc(sizeof(struct user))))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -137,20 +137,20 @@ int do_user_login(int fd, struct vcc_request *req) {
|
|
|
out->uid = 0;
|
|
out->uid = 0;
|
|
|
vcc_send_req(find_connection(fd), out);
|
|
vcc_send_req(find_connection(fd), out);
|
|
|
|
|
|
|
|
- free(usr);
|
|
|
|
|
|
|
+ afree(usr, sizeof(struct user));
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
vcc_log("%s logged in. \n", req->usrname);
|
|
vcc_log("%s logged in. \n", req->usrname);
|
|
|
|
|
|
|
|
- if (unlikely(!(t = malloc(128)))) {
|
|
|
|
|
|
|
+ if (unlikely(!(t = amalloc(128)))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (unlikely(!(n = malloc(sizeof(struct klist_node))))) {
|
|
|
|
|
|
|
+ if (unlikely(!(n = amalloc(sizeof(struct klist_node))))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
@@ -171,7 +171,7 @@ int do_user_login(int fd, struct vcc_request *req) {
|
|
|
sprintf(t, join_msg, req->usrname, nusers);
|
|
sprintf(t, join_msg, req->usrname, nusers);
|
|
|
vcc_message_broadcast(t, "system", 0);
|
|
vcc_message_broadcast(t, "system", 0);
|
|
|
|
|
|
|
|
- free(t);
|
|
|
|
|
|
|
+ afree(t, 128);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -193,6 +193,8 @@ static struct klist_node *find_user(int fd) {
|
|
|
int do_user_logout(int fd) {
|
|
int do_user_logout(int fd) {
|
|
|
struct klist_node *n;
|
|
struct klist_node *n;
|
|
|
struct user *usr;
|
|
struct user *usr;
|
|
|
|
|
+ static const char *leave_msg = "%s left, now there are %d users here. \n";
|
|
|
|
|
+ char *t;
|
|
|
int fdt;
|
|
int fdt;
|
|
|
|
|
|
|
|
if (unlikely(!(n = find_user(fd))))
|
|
if (unlikely(!(n = find_user(fd))))
|
|
@@ -206,13 +208,22 @@ int do_user_logout(int fd) {
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (unlikely(!(t = amalloc(128)))) {
|
|
|
|
|
+ vcc_log("*** malloc() failed\n");
|
|
|
|
|
+
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
write(fdt, usr, sizeof(struct user));
|
|
write(fdt, usr, sizeof(struct user));
|
|
|
vcc_log("Bye, %s. \n", usr->username);
|
|
vcc_log("Bye, %s. \n", usr->username);
|
|
|
|
|
|
|
|
|
|
+ sprintf(t, leave_msg, usr->username, --nusers);
|
|
|
|
|
+ vcc_message_broadcast(t, "system", 0);
|
|
|
|
|
+
|
|
|
klist_del(&logged_users, n);
|
|
klist_del(&logged_users, n);
|
|
|
|
|
|
|
|
- free(usr);
|
|
|
|
|
- free(n);
|
|
|
|
|
|
|
+ afree(usr, sizeof(struct user));
|
|
|
|
|
+ afree(n, sizeof(struct klist_node));
|
|
|
|
|
|
|
|
close(fdt);
|
|
close(fdt);
|
|
|
|
|
|