Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

mg_mgr_free heap corruption using UDP loopback address in windows platform

mg_mgr_free cause heap corruption.

/*
* Copyright (c) 2014-2018 Cesanta Software Limited
* All rights reserved
*
* This program sends provided data to the provided UDP server and port, and
* then prints all incoming data, until user stops the program.
*/

#include "mongoose.h"

#define ADDR_BUF_SIZE 256

static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
    switch (ev) {
    case MG_EV_RECV:
        fprintf(stderr, "%.*s", (int)nc->recv_mbuf.len, nc->recv_mbuf.buf);
        nc->recv_mbuf.len = 0;
        break;
    default:
        break;
    }

    (void)ev_data;
}

int main(int argc, char *argv[]) {
    struct mg_mgr mgr;
    char addr[ADDR_BUF_SIZE];

    mg_mgr_init(&mgr, NULL);



    struct mg_connection *nc = mg_connect(&mgr, "udp://127.0.0.1:17000", ev_handler);
    //struct mg_connection *nc = mg_connect(&mgr, "udp://17000", ev_handler);

    if (nc == NULL) {
        fprintf(stderr, "Failed to connect");
        exit(1);
    }

    const char* data = "hello";

    mg_send(nc, data, strlen(data));

    fprintf(stderr, "Waiting for data\n");

    for (int i = 1; i < 10; i++) {
        mg_mgr_poll(&mgr, 10);
    }
    mg_mgr_free(&mgr);

    return 0;
}

Comments

Sign In or Register to comment.