

#include <stdlib.h>
#include <openssl/crypto.h>
#include "platform.h"            

char **newargv = NULL;

static void cleanup_argv(void)
{
    OPENSSL_free(newargv);
    newargv = NULL;
}

char **copy_argv(int *argc, char *argv[])
{
    

    int i, count = *argc;
    char **p = newargv;

    cleanup_argv();

    
    newargv = OPENSSL_malloc(sizeof(*newargv) * (count + 1));
    if (newargv == NULL)
        return NULL;

    
    if (p == NULL)
        OPENSSL_atexit(cleanup_argv);

    for (i = 0; i < count; i++)
        newargv[i] = argv[i];
    newargv[i] = NULL;
    *argc = i;
    return newargv;
}
