changeset 1599:2b3aee52932a

fix dpip cmd leak
author corvid <corvid@lavabit.com>
date Thu, 04 Mar 2010 01:46:50 +0000
parents 637a98825c4a
children 262bb5afd0f1
files dpi/cookies.c
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Wed Mar 03 18:55:02 2010 +0000
+++ b/dpi/cookies.c	Thu Mar 04 01:46:50 2010 +0000
@@ -1274,7 +1274,7 @@
  */
 static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf)
 {
-   char *cmd, *cookie, *host, *path, *scheme;
+   char *cmd, *cookie, *host, *path;
    int ret = 1;
    size_t BufSize = strlen(Buf);
 
@@ -1293,31 +1293,31 @@
       MSG("(pid %d): Got DpiBye.\n", (int)getpid());
       exit(0);
 
-   } else if (cmd && strcmp(cmd, "set_cookie") == 0) {
+   } else if (strcmp(cmd, "set_cookie") == 0) {
       int st;
       char *date;
 
-      dFree(cmd);
       cookie = a_Dpip_get_attr_l(Buf, BufSize, "cookie");
       host = a_Dpip_get_attr_l(Buf, BufSize, "host");
       path = a_Dpip_get_attr_l(Buf, BufSize, "path");
       date = a_Dpip_get_attr_l(Buf, BufSize, "date");
 
       st = Cookies_set(cookie, host, path, date);
+
+      dFree(cmd);
       cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "set_cookie_answer",
                              st == 0 ? "ok" : "not set");
       a_Dpip_dsh_write_str(sh, 1, cmd);
 
-      dFree(cmd);
       dFree(date);
       dFree(path);
       dFree(host);
       dFree(cookie);
       ret = 2;
 
-   } else if (cmd && strcmp(cmd, "get_cookie") == 0) {
-      dFree(cmd);
-      scheme = a_Dpip_get_attr_l(Buf, BufSize, "scheme");
+   } else if (strcmp(cmd, "get_cookie") == 0) {
+      char *scheme = a_Dpip_get_attr_l(Buf, BufSize, "scheme");
+
       host = a_Dpip_get_attr_l(Buf, BufSize, "host");
       path = a_Dpip_get_attr_l(Buf, BufSize, "path");
 
@@ -1326,6 +1326,7 @@
       dFree(path);
       dFree(host);
 
+      dFree(cmd);
       cmd = a_Dpip_build_cmd("cmd=%s cookie=%s", "get_cookie_answer", cookie);
 
       if (a_Dpip_dsh_write_str(sh, 1, cmd)) {
@@ -1335,8 +1336,8 @@
           ret = 2;
       }
       dFree(cookie);
-      dFree(cmd);
    }
+   dFree(cmd);
 
    return ret;
 }