﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
361	psMetadataItemAllocV over-allocates memory for comment	eugene	robert.desonia@…	"the specific problem is in lines 187-194:

    // Allocate and set metadata item comment
    metadataItem->comment = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
    if (comment == NULL) {
        // Per SDRS, null isn't allowed, must use """" instead
        strncpy(metadataItem->comment, """", MAX_STRING_LENGTH);
    } else {
        strncpy(metadataItem->comment, comment, MAX_STRING_LENGTH);
    }


this is allocating a potentially huge block of data, when we really only need a
minimal chunk which can in principal be measured by strlen().  

the more fundamental problem is that the code is not making use of the low-level
functionalities already in psLib:  psStringCopy.  here is how I would have done
this:

    // set metadata item comment
    if (comment == NULL) {
        // Per SDRS, null isn't allowed, must use """" instead
        metadataItem->comment = psStringCopy ("""");
    } else {
        metadataItem->comment = psStringCopy (comment);
    }

(now, even if we have a blanket policy that strings are always allocated in
large chunks, for efficiency's sake, we have isolated that policy decision to a
single function)."	defect	closed	high		types	0.5.0	normal	fixed		
