Zaid Pirwani

Co-Founder / Engineer at EjaadTech + Industrial Electronics Engineer + all round Computer/Electronics Geek

Leaky Code…

I had heard lots and lots about leaky code so far, but never actually learned about it or read about it until tonight… so here it is below: a sample of LEAKY CODE (source: Wikipedia)

#include <stdlib.h>
void function_which_allocates(void) {
    /* allocate an array of 45 floats */
    float * a = malloc(sizeof(float) * 45);
    /* additional code making use of 'a' */
    /* return to main, having forgotten to free the memory we malloc'd */
int main(void) {
    /* the pointer 'a' no longer exists, and therefore cannot be freed,
     but the memory is still allocated. a leak has occurred. */

via Wikipedia Memory Leak Article

comment bhi kar hi dain.. :P

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: