mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-26 21:13:11 +01:00
phkmalloc strikes!
#ifdef out a number of calls to free() left over from the original GNU ypserv implementation. As near as I can tell, the Berkeley DB package does its own garbage collection, hence the caller doesn't have to worry about free()ing the memory returned in the DBT structures during lookups (I'm still not 1005 sure about this: the DB code is very hard to follow. I must use dynamically allocated memory since you can retreive arbitrarily large records from a database, but I'm not sure where it ends up letting go of it). This was not true with GDBM; you had to do your own garbage collection. The general rule is that if you allocate memory inside an RPC service routine, you have to free() it the next time the routine is called since the underlying XDR routines won't do it for you. But if the DB package does this itself, then we don't need to do it in the main program. Note that with the original malloc(), there were never any errors flagged. phkmalloc complained quite loudly.
This commit is contained in:
parent
b025187719
commit
336844dba4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=10986
@ -24,7 +24,7 @@
|
||||
** Ported to FreeBSD and hacked all to pieces
|
||||
** by Bill Paul <wpaul@ctr.columbia.edu>
|
||||
**
|
||||
** $Id: server.c,v 1.7 1995/07/02 18:48:21 wpaul Exp $
|
||||
** $Id: server.c,v 1.11 1995/07/15 23:27:47 wpaul Exp $
|
||||
**
|
||||
*/
|
||||
|
||||
@ -349,7 +349,9 @@ int read_database(DB *dbp,
|
||||
}
|
||||
if ((dbp->seq)(dbp,&ckey,&dummyval,R_NEXT))
|
||||
ckey.data = NULL;
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(dummyval.data);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
ckey = *ikey;
|
||||
@ -364,10 +366,11 @@ int read_database(DB *dbp,
|
||||
{
|
||||
if ((dbp->get)(dbp,&ckey,dval,0))
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
/* Free key, unless it comes from the caller! */
|
||||
if (ikey == NULL || ckey.data != ikey->data)
|
||||
free(ckey.data);
|
||||
|
||||
#endif
|
||||
if (ikey && ikey->data != NULL)
|
||||
{
|
||||
return YP_NOKEY;
|
||||
@ -383,23 +386,26 @@ int read_database(DB *dbp,
|
||||
{
|
||||
if (okey)
|
||||
*okey = ckey;
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
else if (ikey == NULL || ikey->data != ckey.data)
|
||||
free(ckey.data);
|
||||
|
||||
#endif
|
||||
return YP_TRUE;
|
||||
}
|
||||
|
||||
/* Free old value */
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(dval->data);
|
||||
|
||||
#endif
|
||||
if ((dbp->seq)(dbp,&nkey,&dummyval,R_NEXT))
|
||||
nkey.data = NULL;
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(dummyval.data);
|
||||
|
||||
/* Free old key, unless it comes from the caller! */
|
||||
if (ikey == NULL || ckey.data != ikey->data)
|
||||
free(ckey.data);
|
||||
|
||||
#endif
|
||||
if (ckey.data == NULL || nkey.data == NULL)
|
||||
return YP_NOMORE;
|
||||
|
||||
@ -481,7 +487,17 @@ ypresp_val *ypproc_match_2_svc(ypreq_key *key,
|
||||
result.val.valdat_len = 0;
|
||||
if (result.val.valdat_val)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
/*
|
||||
* In general, if you malloc() data in an RPC service
|
||||
* routine, you have to free() it the next time that
|
||||
* routine is called since the XDR routines won't free
|
||||
* it for you. However, in this case, we don't have to
|
||||
* do that because the DB routines do garbage collection
|
||||
* for us.
|
||||
*/
|
||||
free(result.val.valdat_val);
|
||||
#endif
|
||||
result.val.valdat_val = NULL;
|
||||
}
|
||||
|
||||
@ -629,14 +645,18 @@ ypresp_key_val *ypproc_first_2_svc(ypreq_nokey *key,
|
||||
result.key.keydat_len = 0;
|
||||
if (result.key.keydat_val)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(result.key.keydat_val);
|
||||
#endif
|
||||
result.key.keydat_val = NULL;
|
||||
}
|
||||
|
||||
result.val.valdat_len = 0;
|
||||
if (result.val.valdat_val)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(result.val.valdat_val);
|
||||
#endif
|
||||
result.val.valdat_val = NULL;
|
||||
}
|
||||
|
||||
@ -732,14 +752,18 @@ ypresp_key_val *ypproc_next_2_svc(ypreq_key *key,
|
||||
result.key.keydat_len = 0;
|
||||
if (result.key.keydat_val)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(result.key.keydat_val);
|
||||
#endif
|
||||
result.key.keydat_val = NULL;
|
||||
}
|
||||
|
||||
result.val.valdat_len = 0;
|
||||
if (result.val.valdat_val)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(result.val.valdat_val);
|
||||
#endif
|
||||
result.val.valdat_val = NULL;
|
||||
}
|
||||
|
||||
@ -1096,7 +1120,9 @@ ypresp_master *ypproc_master_2_svc(ypreq_nokey *nokey,
|
||||
|
||||
if (result.peer)
|
||||
{
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(result.peer);
|
||||
#endif
|
||||
result.peer = NULL;
|
||||
}
|
||||
|
||||
@ -1117,9 +1143,6 @@ ypresp_master *ypproc_master_2_svc(ypreq_nokey *nokey,
|
||||
key.data = "YP_MASTER_NAME";
|
||||
|
||||
if ((dbp->get)(dbp,&key,&val,0))
|
||||
val.data = NULL;
|
||||
|
||||
if (val.data == NULL)
|
||||
{
|
||||
/* No YP_MASTER_NAME record in map? Assume we are Master */
|
||||
static char hostbuf[1025];
|
||||
@ -1208,8 +1231,7 @@ ypresp_order *ypproc_order_2_svc(ypreq_nokey *nokey,
|
||||
key.size = sizeof("YP_LAST_MODIFIED")-1;
|
||||
key.data = "YP_LAST_MODIFIED";
|
||||
|
||||
(dbp->get)(dbp,&key,&val,0);
|
||||
if (val.data == NULL)
|
||||
if ((dbp->get)(dbp,&key,&val,0))
|
||||
{
|
||||
/* No YP_LAST_MODIFIED record in map? Use DTM timestamp.. */
|
||||
result.ordernum = get_dtm(nokey->domain, nokey->map);
|
||||
@ -1217,7 +1239,9 @@ ypresp_order *ypproc_order_2_svc(ypreq_nokey *nokey,
|
||||
else
|
||||
{
|
||||
result.ordernum = atoi(val.data);
|
||||
#ifdef GNU_YPSERV_ARTIFACT
|
||||
free(val.data);
|
||||
#endif
|
||||
}
|
||||
|
||||
result.stat = YP_TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user