if (buf) OPENSSL_free(buf);
static ASN1_INTEGER *load_serial(char *CAfile, char *serialfile, int create)	{	char *buf = NULL, *p;	MS_STATIC char buf2[1024];	ASN1_INTEGER *bs = NULL, bs2;	BIO *io = NULL;	BIGNUM *serial = NULL;	buf=OPENSSL_malloc( ((serialfile == NULL)			?(strlen(CAfile)+strlen(POSTFIX)+1)			:(strlen(serialfile)))+1);	if (buf == NULL) { BIO_printf(bio_err,"out of mem\n"); goto end; }	if (serialfile == NULL)		{		strcpy(buf,CAfile);		for (p=buf; *p; p++)			if (*p == '.')				{				*p='\0';				break;				}		strcat(buf,POSTFIX);		}	else		strcpy(buf,serialfile);	serial=BN_new();	bs=ASN1_INTEGER_new();	if ((serial == NULL) || (bs == NULL))		{		ERR_print_errors(bio_err);		goto end;		}	io=BIO_new(BIO_s_file());	if (io == NULL)		{		ERR_print_errors(bio_err);		goto end;		}		if (BIO_read_filename(io,buf) <= 0)		{		if (!create)			{			perror(buf);			goto end;			}		else			{			ASN1_INTEGER_set(bs,1);			BN_one(serial);			}		}	else 		{		if (!a2i_ASN1_INTEGER(io,bs,buf2,1024))			{			BIO_printf(bio_err,"unable to load serial number from %s\n",buf);			ERR_print_errors(bio_err);			goto end;			}		else			{			serial=BN_bin2bn(bs->data,bs->length,serial);			if (serial == NULL)				{				BIO_printf(bio_err,"error converting bin 2 bn");				goto end;				}			}		}	if (!BN_add_word(serial,1))		{ BIO_printf(bio_err,"add_word failure\n"); goto end; }	bs2.data=(unsigned char *)buf2;	bs2.length=BN_bn2bin(serial,bs2.data);	if (BIO_write_filename(io,buf) <= 0)		{		BIO_printf(bio_err,"error attempting to write serial number file\n");		perror(buf);		goto end;		}	i2a_ASN1_INTEGER(io,&bs2);	BIO_puts(io,"\n");	BIO_free(io);	io=NULL;	return bs;	end:	BIO_free(io);	ASN1_INTEGER_free(bs);	BN_free(serial);	return NULL;	}