free(filename) to avoid memory leak. Add some "const" and "static"
authorRoker <roker@pep-project.org>
Wed, 13 Jul 2016 23:13:41 +0200
changeset 8620f0414b15c72
parent 861 03f1f3d3858a
child 863 c4d31c928b9f
child 864 b0be088fbcb7
free(filename) to avoid memory leak. Add some "const" and "static"
src/message_api.c
     1.1 --- a/src/message_api.c	Wed Jul 13 19:49:53 2016 +0200
     1.2 +++ b/src/message_api.c	Wed Jul 13 23:13:41 2016 +0200
     1.3 @@ -751,13 +751,11 @@
     1.4  
     1.5  static char * without_double_ending(const char *filename)
     1.6  {
     1.7 -    char *ext;
     1.8 -
     1.9      assert(filename);
    1.10      if (filename == NULL)
    1.11          return NULL;
    1.12      
    1.13 -    ext = strrchr(filename, '.');
    1.14 +    char *ext = strrchr(filename, '.');
    1.15      if (ext == NULL)
    1.16          return NULL;
    1.17  
    1.18 @@ -1366,11 +1364,8 @@
    1.19                      }
    1.20                      else if (is_encrypted_attachment(_s)) {
    1.21                          stringlist_t *_keylist = NULL;
    1.22 -                        char *attctext;
    1.23 -                        size_t attcsize;
    1.24 -
    1.25 -                        attctext = _s->value;
    1.26 -                        attcsize = _s->size;
    1.27 +                        char *attctext  = _s->value;
    1.28 +                        size_t attcsize = _s->size;
    1.29  
    1.30                          free(ptext);
    1.31                          ptext = NULL;
    1.32 @@ -1387,8 +1382,8 @@
    1.33                                      goto pep_error;
    1.34                              }
    1.35                              else {
    1.36 -                                char * mime_type = "application/octet-stream";
    1.37 -                                char * filename =
    1.38 +                                static const char * const mime_type = "application/octet-stream";
    1.39 +                                const char * const filename =
    1.40                                      without_double_ending(_s->filename);
    1.41                                  if (filename == NULL)
    1.42                                      goto enomem;
    1.43 @@ -1401,6 +1396,7 @@
    1.44  
    1.45                                  _m = bloblist_add(_m, _ptext, psize, mime_type,
    1.46                                      filename);
    1.47 +                                free(filename);
    1.48                                  if (_m == NULL)
    1.49                                      goto enomem;
    1.50