Commit 1057c2c3 authored by Viktor Dukhovni's avatar Viktor Dukhovni
Browse files

Cleaner disposal of ephemeral engine ids and names



Engine names and ids are typically static strings.  If an application
actually dynamically allocated these, the application owns the
storage, and should dispose of it via the original handle, rather
than the "const char *" returned by the engine.

In any case, this resolves the test code issue without resort to
"unconst" macros/casts.

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent 9b340281
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -44,8 +44,9 @@ static void display_engine_list(void)
static int test_engines(void)
{
    ENGINE *block[NUMTOADD];
    char *eid[NUMTOADD];
    char *ename[NUMTOADD];
    char buf[256];
    const char *id, *name;
    ENGINE *ptr;
    int loop;
    int to_return = 0;
@@ -138,12 +139,12 @@ static int test_engines(void)
    TEST_info("About to beef up the engine-type list");
    for (loop = 0; loop < NUMTOADD; loop++) {
        sprintf(buf, "id%d", loop);
        id = OPENSSL_strdup(buf);
        eid[loop] = OPENSSL_strdup(buf);
        sprintf(buf, "Fake engine type %d", loop);
        name = OPENSSL_strdup(buf);
        ename[loop] = OPENSSL_strdup(buf);
        if (!TEST_ptr(block[loop] = ENGINE_new())
                || !TEST_true(ENGINE_set_id(block[loop], id))
                || !TEST_true(ENGINE_set_name(block[loop], name)))
                || !TEST_true(ENGINE_set_id(block[loop], eid[loop]))
                || !TEST_true(ENGINE_set_name(block[loop], ename[loop])))
            goto end;
    }
    for (loop = 0; loop < NUMTOADD; loop++) {
@@ -162,8 +163,8 @@ static int test_engines(void)
        ENGINE_free(ptr);
    }
    for (loop = 0; loop < NUMTOADD; loop++) {
        OPENSSL_free((void *)(intptr_t)ENGINE_get_id(block[loop]));
        OPENSSL_free((void *)(intptr_t)ENGINE_get_name(block[loop]));
        OPENSSL_free(eid[loop]);
        OPENSSL_free(ename[loop]);
    }
    to_return = 1;

+2 −2

File changed.

Contains only whitespace changes.