Re: [PATCH v2] winemapi: Directly use xdg-email if available, enabling file attachments.
On Thu, 2016-11-17 at 13:43 -0600, Jeremy White wrote:
+static ULONG add_argument(char **argv, int *argc, const char *arg, const char *param) +{ + argv[(*argc)] = HeapAlloc(GetProcessHeap(), 0, strlen(arg) + 1); + if (!argv[(*argc)]) + return MAPI_E_INSUFFICIENT_MEMORY; + strcpy(argv[(*argc)++], arg); + + if (param) + { + argv[(*argc)] = HeapAlloc(GetProcessHeap(), 0, strlen(param) + 1); + if (!argv[(*argc)]) + return MAPI_E_INSUFFICIENT_MEMORY; + strcpy(argv[(*argc)++], param); + } + + return SUCCESS_SUCCESS;
This still leaks when the first allocation succeeds and the second fails.
+static ULONG add_file(char **argv, int *argc, const char *path, const char *file) +{ + WCHAR *fullname, *p; + char *unixpath; + int namelen = 1; + ULONG ret; + + if (path) + namelen += strlen(path) + 1; + if (file) + namelen += strlen(file); + + p = fullname = HeapAlloc(GetProcessHeap(), 0, namelen * sizeof(WCHAR)); + if (!fullname) + return MAPI_E_INSUFFICIENT_MEMORY; + memset(fullname, 0, namelen * sizeof(WCHAR));
You should pass HEAP_ZERO_MEMORY to HeapAlloc if you need a zero-initialized block but in this case it's sufficient to initialize the first element of fullname.
+ if (path) + { + MultiByteToWideChar(CP_ACP, 0, path, -1, p, namelen); + p += strlen(path); + MultiByteToWideChar(CP_ACP, 0, "\\", 1, p, 1); + p++;
This is shorter and doesn't make an assumption about conversion length: p += MultiByteToWideChar(CP_ACP, 0, path, -1, p, namelen);
+ULONG XDGSendMail(LHANDLE session, ULONG_PTR uiparam, + lpMapiMessage message, FLAGS flags, ULONG reserved) +{ + int i; + int argc = 0; + int max_args; + char **argv = NULL; + ULONG ret; + + TRACE("(0x%08lx 0x%08lx %p 0x%08x 0x%08x)\n", session, uiparam, message, flags, reserved); + + if (!message) + return MAPI_E_FAILURE; + + max_args = 1 + (2 + message->nRecipCount + message->nFileCount) * 2; + argv = HeapAlloc(GetProcessHeap(), 0, (max_args + 1) * sizeof(*argv)); + if (!argv) + return MAPI_E_INSUFFICIENT_MEMORY; + + memset(argv, 0, (max_args + 1) * sizeof(*argv));
See above.
participants (1)
-
Hans Leidekker